I'm trying implement periodic tasks in django app by using celery (v 4.3.0). My tasks.py
looks like below:
# forepy is the simple package created by me
from forepy import Instrument
from forepy import oanda_api
from celery import shared_task
@shared_task
def sum_numbers(a, b):
return a + b
Problem is that celery worker returns error Received unregistered task of type 'fxsignal.tasks.sum_number'
. I think that cause of problem is two import statements at the top of tasks.py
(forepy imports). When I comment out those two lines my periodic task sum_numbers
works correctly. For your reference, structure of forepy
package is as below:
forepy\
downloaders\
__init.py__
oanda_api.py
__init__.py
instruments.py
utils.py
And forepy
's init.py:
# -*- coding: utf-8 -*-
"""Top-level package for forepy."""
__author__ = """Elgin Jahangirov"""
__email__ = 'cahangirove@gmail.com'
__version__ = '0.2.0'
from forepy.instrument import Instrument
from forepy.downloaders import oanda_api
__all__ = ['Instrument', 'oanda_api']
I've read this part of celery documentation and get rid of all .
imports in my forepy
package, but still problem exists. What can I do further to solve this problem?
Celery failed silently in this case, although one of dependency of another package (which is dependency of forepy
) is not installed in current environment. I can only detect that after adding below configuration in django project's settings.py
(thanks to @cagrias):
CELERY_IMPORTS = (
'your_app.tasks',
'forepy.instrument',
'forepy.downloaders',
)
By adding above configuration to django settings, terminal reported import error, which was actual cause of not registering task.