Answer the question
In order to leave comments, you need to log in
How to call a function from task in celery?
There is a function in the directory
app/stats/views.py
@task(name='Sorting response')
def sorting_task_response(*args):
pass
app/api/tasks.py
from __future__ import absolute_import, unicode_literals
# Create your tasks here
import random
import requests
import json
from datetime import datetime
from celery import task, shared_task, Task, group, chord
from stats.views import sorting_task_response
class NotifierTask(Task):
"""
Tasks that sends notification on completion.
"""
abstract = True
def after_return(self, status, retval, task_id, args, kwargs, einfo):
print(status, retval, task_id, args, kwargs, einfo)
print('Task done')
def notify_client_ws(token, response):
data = dict(token=token, notice=response[0])
url = 'http://ws_server:8060/ws/celery/response'
resp = requests.post(url, data=json.dumps(data))
# Celery callback
@task(name='CallbackNotifier')
def callback_notifier(*args, **kwargs):
tasks_response = kwargs.get("tasks_response")
notify_client_ws(token=kwargs.get("user_token"), response=args)
return True
@task(name='Data after receiving statistics')
def stats_result(*args, **kwargs):
sorting_task_response.d(args)
flower_1 | File "/app/api/tasks.py", line 8, in <module>
flower_1 | from stats.views import sorting_task_response
flower_1 | ImportError: cannot import name 'sorting_task_response'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question