Search code examples
djangoamazon-web-servicescelerydjango-celery

How to fix "Error Removing corrupted schedule file 'celerybeat-schedule': error('Bad magic number',)r"


I can run the celery beat normally using the command in the terminal, but when I go to run in aws, I get the following error:

[2019-07-10 11:30:35,166: ERROR/MainProcess] Removing corrupted schedule file 'celerybeat-schedule': error('Bad magic number',)
    Traceback (most recent call last):
      File "/opt/python/run/venv/local/lib/python3.6/site-packages/kombu/utils/objects.py", line 42, in __get__
        return obj.__dict__[self.__name__]
    KeyError: 'scheduler'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/opt/python/run/venv/local/lib/python3.6/site-packages/celery/beat.py", line 476, in setup_schedule
        self._store = self._open_schedule()
      File "/opt/python/run/venv/local/lib/python3.6/site-packages/celery/beat.py", line 466, in _open_schedule
        return self.persistence.open(self.schedule_filename, writeback=True)
      File "/usr/lib64/python3.6/shelve.py", line 243, in open
        return DbfilenameShelf(filename, flag, protocol, writeback)
      File "/usr/lib64/python3.6/shelve.py", line 227, in __init__
        Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
      File "/usr/lib64/python3.6/dbm/__init__.py", line 94, in open
        return mod.open(file, flag, mode)
    _gdbm.error: Bad magic number

Could someone please help me to understand whats's wrong?


Solution

  • taken from the site.

    Beat needs to store the last run times of the tasks in a local database file (named celerybeat-schedule by default), so it needs access to write in the current directory, or alternatively you can specify a custom location for this file:

    celery -A proj beat -s /home/celery/var/run/celerybeat-schedule