celery / django-celery-beat

Celery Periodic Tasks backed by the Django ORM
Other
1.7k stars 428 forks source link

Problem when using django-celery-beat in two projects sharing the same database #579

Open Kinzowa opened 2 years ago

Kinzowa commented 2 years ago

Hello,

I have two Django projects that share the same database, and both project have django-celery-beat installed. The problem I have with this configuration is that periodic tasks from one project are detected by the other project as unregistered and REJECTED. They do not appear in the Periodic tasks admin section of the other project because they are unregistered but log show there is an issue.

I believe the reason is that the two django-celery-beat applications share the same tables of the shared database.

Could you tell me what is the best solution to address the issue ? Do you think I could change the name of the application so that 2 django-celery-beat live separatly in the database ?

Thank you

project-a-celery_worker-1  | 2022-09-09T11:35:15.974463294Z Received unregistered task of type 'trading.tasks.bulk_trade'.
project-a-celery_worker-1  | 2022-09-09T11:35:15.974621504Z The message has been ignored and discarded.
project-a-celery_worker-1  | 2022-09-09T11:35:15.974655749Z 
project-a-celery_worker-1  | 2022-09-09T11:35:15.974677303Z Did you remember to import the module containing this task?
project-a-celery_worker-1  | 2022-09-09T11:35:15.974699464Z Or maybe you're using relative imports?
project-a-celery_worker-1  | 2022-09-09T11:35:15.974721029Z 
project-a-celery_worker-1  | 2022-09-09T11:35:15.974741804Z Please see
project-a-celery_worker-1  | 2022-09-09T11:35:15.974782954Z http://docs.celeryq.org/en/latest/internals/protocol.html
project-a-celery_worker-1  | 2022-09-09T11:35:15.974815238Z for more information.
project-a-celery_worker-1  | 2022-09-09T11:35:15.974839132Z 
project-a-celery_worker-1  | 2022-09-09T11:35:15.974897495Z The full contents of the message body was:
project-a-celery_worker-1  | 2022-09-09T11:35:15.974938229Z b'[[], {}, {"callbacks": null, "errbacks": null, "chain": null, "chord": null}]' (77b)
project-a-celery_worker-1  | 2022-09-09T11:35:15.974982482Z 
project-a-celery_worker-1  | 2022-09-09T11:35:15.975032349Z Thw full contents of the message headers:
project-a-celery_worker-1  | 2022-09-09T11:35:15.975090058Z {'lang': 'py', 'task': 'trading.tasks.bulk_trade', 'id': 'd86620c2-04ab-4b59-bb2e-77685389f8d5', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'group_index': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'd86620c2-04ab-4b59-bb2e-77685389f8d5', 'parent_id': None, 'argsrepr': '()', 'kwargsrepr': '{}', 'origin': 'gen9@03298c28290e', 'ignore_result': False}
project-a-celery_worker-1  | 2022-09-09T11:35:15.975125751Z 
project-a-celery_worker-1  | 2022-09-09T11:35:15.975194550Z The delivery info for this task is:
project-a-celery_worker-1  | 2022-09-09T11:35:15.975257110Z {'exchange': '', 'routing_key': 'project-a_queue_1'}
project-a-celery_worker-1  | 2022-09-09T11:35:15.981241271Z  exc_info=(<class 'KeyError'>, KeyError('trading.tasks.bulk_trade'), <traceback object at 0x7fe49ca1b8c0>)
project-a-celery_worker-1  | 2022-09-09T11:35:15.996976839Z [error    ] task_not_found                              [django_structlog.celery.receivers] message=<Message object at 0x7fe49cb6e680 with details {'state': 'REJECTED', 'content_type': 'application/json', 'delivery_tag': '43925569-3d7a-4272-9629-2e08581f6579', 'body_length': 77, 'properties': {'correlation_id': 'd86620c2-04ab-4b59-bb2e-77685389f8d5'}, 'delivery_info': {'exchange': '', 'routing_key': 'project-a_queue_1'}}>
auvipy commented 2 years ago

can you check this https://github.com/celery/django-celery-beat/pull/451 PR?