cic-internal-integration/apps/cic-eth/cic_eth/callbacks/redis.py

29 lines
735 B
Python
Raw Permalink Normal View History

2021-02-01 18:12:51 +01:00
# standard imports
import logging
import json
import redis as redis_interface
# third-party imports
import celery
# local imports
from . import Callback
celery_app = celery.current_app
logg = celery_app.log.get_default_logger()
@celery_app.task(base=Callback, bind=True)
def redis(self, result, destination, status_code):
(host, port, db, channel) = destination.split(':')
r = redis_interface.Redis(host=host, port=port, db=db)
2021-02-21 16:41:37 +01:00
data = {
'root_id': self.request.root_id,
'status': status_code,
'result': result,
}
2021-02-01 18:12:51 +01:00
logg.debug('redis callback on host {} port {} db {} channel {}'.format(host, port, db, channel))
2021-02-21 16:41:37 +01:00
r.publish(channel, json.dumps(data))
2021-02-01 18:12:51 +01:00
r.close()