Answer the question
In order to leave comments, you need to log in
Why doesn't the simplest script with celery beat work?
A simple script throws an error.
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'rik_ahrefs.settings')
celery = Celery('rik_ahrefs', broker='pyamqp://[email protected]//', backend='rpc://celery_backend')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
celery.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
celery.autodiscover_tasks()
celery.conf.beat_schedule = {
'scan_master_sheet': {
'task': 'tasks.scan_master_sheet',
'schedule': 15.0,
#'args': ('X','Z')
},
}
@celery.task()
def scan_master_sheet(self):
print('A!')
(venv) E:\Work\rik_ahrefs>celery -A tasks beat
celery beat v4.2.0 (windowlicker) is starting.
__ - ... __ - _
LocalTime -> 2018-07-14 18:13:08
Configuration ->
. broker -> amqp://guest:**@localhost:5672//
. loader -> celery.loaders.app.AppLoader
. scheduler -> celery.beat.PersistentScheduler
. db -> celerybeat-schedule
. logfile -> [stderr]@%WARNING
. maxinterval -> 5.00 minutes (300s)
[2018-07-14 18:13:08,307: ERROR/MainProcess] Message Error: Couldn't apply scheduled task scan_master_sheet: scan_master_sheet() missing 1 required positional argument: 'self'
[' File "C:\\Python36\\lib\\runpy.py", line 193, in _run_module_as_main\n "__main__", mod_spec)\n', ' File "C:\\Python36\\lib\\runpy.py", line 85, in _run_code\n exec(code, run_globals)\n', ' File "E:\\Work\\rik_ahrefs\\venv\\Scripts\\celery.exe\\__main__.py", line 9, in <module>\n sys.exit(main())\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\__main__.py", line 16, in main\n _main()\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\celery.py", line 322, in main\n cmd.execute_from_commandline(argv)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\celery.py", line 496, in execute_from_commandline\n super(CeleryCommand, self).execute_from_commandline(argv)))\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\base.py", line 275, in execute_from_commandline\n return self.handle_argv(self.prog_name, argv[1:])\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\celery.py", line 488, in handle_argv\n return self.execute(command, argv)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\celery.py", line 420, in execute\n ).run_from_argv(self.prog_name, argv[1:], command=argv[0])\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\base.py", line 279, in run_from_argv\n sys.argv if argv is None else argv, command)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\base.py", line 363, in handle_argv\n return self(*args, **options)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\base.py", line 238, in __call__\n ret = self.run(*args, **kwargs)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\bin\\beat.py", line 109, in run\n return beat().run()\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\apps\\beat.py", line 81, in run\n self.start_scheduler()\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\apps\\beat.py", line 109, in start_scheduler\n service.start()\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\beat.py", line 588, in start\n interval = self.scheduler.tick()\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\beat.py", line 307, in tick\n self.apply_entry(entry, producer=self.producer)\n', ' File "e:\\work\\rik_ahrefs\\venv\\lib\\site-packages\\celery\\beat.py", line 244, in apply_entry\n exc, traceback.format_stack(), exc_info=True)\n']
Traceback (most recent call last):
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\beat.py", line 350, in apply_async
**entry.options)
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\app\task.py", line 513, in apply_async
check_arguments(*(args or ()), **(kwargs or {}))
TypeError: scan_master_sheet() missing 1 required positional argument: 'self'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\beat.py", line 241, in apply_entry
result = self.apply_async(entry, producer=producer, advance=False)
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\beat.py", line 358, in apply_async
entry, exc=exc)), sys.exc_info()[2])
File "e:\work\rik_ahrefs\venv\lib\site-packages\vine\five.py", line 178, in reraise
raise value.with_traceback(tb)
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\beat.py", line 350, in apply_async
**entry.options)
File "e:\work\rik_ahrefs\venv\lib\site-packages\celery\app\task.py", line 513, in apply_async
check_arguments(*(args or ()), **(kwargs or {}))
celery.beat.SchedulingError: Couldn't apply scheduled task scan_master_sheet: scan_master_sheet() missing 1 required positional argument: 'self'
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