redbeat
redbeat copied to clipboard
RedBeatSchedulerEntry won't works without specifying the app
Hi,
I'm playing with redbeat, but I faced to an error with a code similar to the tutorial code. Here the minimal code to reproduce :
tasks.py
from celery import Celery
app = Celery()
app.config_from_object('redbeatconf')
@app.task
def test(arg):
print(arg)
redbeatconf.py
redbeat_redis_url = "redis://localhost:6379/1"
beat_scheduler = "redbeat.RedBeatScheduler"
test.py
from celery.schedules import schedule, crontab
from redbeat import RedBeatSchedulerEntry
if __name__ == '__main__':
entry = RedBeatSchedulerEntry('say-hello', 'tasks.test',
schedule(run_every=10), args=['hello world !'])
entry.save()
I get this error :
$ python3 test.py
Traceback (most recent call last):
File "test.py", line 10, in <module>
entry.save()
File "/usr/local/lib/python3.5/dist-packages/redbeat/schedulers.py", line 209, in save
pipe.hset(self.key, 'definition', json.dumps(definition, cls=RedBeatJSONEncoder))
File "/usr/local/lib/python3.5/dist-packages/redbeat/schedulers.py", line 188, in key
return self.app.redbeat_conf.key_prefix + self.name
AttributeError: 'NoneType' object has no attribute 'redbeat_conf'
To avoid this error, I need (in test.py):
- to create or import a valid app
- to add
app=app
in theRedBeatSchedulerEntry
arguments.
Is it normal ?
Thank you
Most likely yes, Celery 4.0 moved to a more explicit context model for passing app around. I don't have the link handy but unless you set a global default you will need to pass app into RedBeatSchedulerEntry.
I've dropped support for Celery 3.0. I don't know if that makes it easier to solve for this case or not.