0

When I try to run this code it throws an error, I want to run task_number_one and print_test as a periodic task but it throws the same error for both.

from celery.task import periodic_task
from celery.schedules import crontab
from celery import task
@task()
def task_number_one():
    print("Celery Task Working...")

@periodic_task(run_every=crontab(minute='10', hour='6,8,9,10,11,12'))
def print_test():
   print(1)

task_number_one.delay()

I get this below error

[2019-09-18 17:21:17,093: ERROR/MainProcess] Received unregistered task of type 'page.tasks.task_number_one'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you're using relative imports?

Please see
http://docs.celeryq.org/en/latest/internals/protocol.html
for more information.

The full contents of the message body was:
'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' (77b)
Traceback (most recent call last):
  File "/home/naanal/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 559, in on_task_received
    strategy = strategies[type_]
KeyError: 'page.tasks.task_number_one'
2

1 Answer 1

0

If you are using celery v4, you register a task differently than you do with v3. For v4 use the following:

from myapp.celery import app

@app.task
def task_number_one():
    print("Celery Task Working...")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.