S
S
sortfact3332021-02-18 14:37:22
Django
sortfact333, 2021-02-18 14:37:22

How to run periodic_task?

I am trying to run the code once per minute

from celery.schedules import crontab
from celery.decorators import periodic_task
# from celery.task import periodic_task
@periodic_task(run_every=crontab(minute='*/1'))
def my_task():
  print('Test')


But I am getting an error

File "c:\users\admin\appdata\local\programs\python\python37\lib\importlib_init_.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 967, in _find_and_load_unlocked File "", line 677, in _load_unlocked
File "", line 728, in exec_module File "", line 219, in _call_with_frames_removed File "D:\Work\Project\git\shop\apps\offers\tasks.py", line 32, in @periodic_task(run_every=crontab(minute='*/1')) File "c:\users\admin \appdata\local\programs\python\python37\lib\site-packages\celery\local.py", line 403, in _compat_periodic_task_decorator from celery.task import periodic_task ModuleNotFoundError: No module named 'celery.task'


As I understand it, celery.task is no longer used
and an analogue is needed, but I don’t know what it looks like.
I even changed celery.task to celery.decorators but didn't help.

Can anyone tell me what my code should look like in order for it to work?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question