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-20 11:29:11 +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-20 11:29:11 +01:00
|
|
|
r.publish(channel, json.dumps(data))
|
2021-02-01 18:12:51 +01:00
|
|
|
r.close()
|