redbeat icon indicating copy to clipboard operation
redbeat copied to clipboard

RedBeatSchedulerEntry won't works without specifying the app

Open yoch opened this issue 7 years ago • 2 comments

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):

  1. to create or import a valid app
  2. to add app=app in the RedBeatSchedulerEntry arguments.

Is it normal ?

Thank you

yoch avatar Sep 28 '17 18:09 yoch

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.

sibson avatar Apr 01 '18 01:04 sibson

I've dropped support for Celery 3.0. I don't know if that makes it easier to solve for this case or not.

sibson avatar Aug 20 '19 02:08 sibson