-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
celery-beat, DatabaseScheduler and per-tenant schedule #100
Comments
you mean it is impossible to have periodic tasks stored in the database, on a per-tenant basis? |
You can, but only from |
Do you have the periodic tasks inserted dynamically into the DB, or are they sourced from your source code? |
It was tested with tasks, described in model |
I believe the |
Yes. You missed django-celery-beat - Celery Periodic Tasks backed by the Django ORM (as wrote in About section). It's simple and clear. Except one - celery-beat don't know about tenants. And if my clients = tenants - I have a way to make manipulation with task's schedule through admin individually by client. One client want to run, for example, some data imports each day at 3, but other - only weekly. And third client don't use this task at all. Project https://github.com/QuickRelease/django-tenants-celery-beat collects all tasks from all tenants to one model, placed in
|
Since you are adding the tasks dynamically to the DB, have you tried adding the `_schema_name: "<your_schema>" kwarg to the task? |
How can it helps me? How can it helps standard DatabasScheduler to go to tenants and find model with PeriodicTasks there? |
The |
My customized DatabaseScheduler pulls tasks from all schemas, not only from public and send them onto queue. No need to save tasks from one schema to another, or make any other job. It just works. |
@Guest007 thank you for this code, could you please share your |
For example in settings.py PROJECT_APPS = [
"some_your_app",
...
]
INSTALLED_APPS = [
"django.contrib.admin",
...
"django_celery_beat",
....
] + PROJECT_APPS
TENANT_SPECIFIC_APPS = [
"django_tenants",
"customers_as_in_django_tenants_docs",
]
SHARED_APPS = TENANT_SPECIFIC_APPS + INSTALLED_APPS # in public schema
TENANT_APPS = INSTALLED_APPS # in tenant schemas for each client.
INSTALLED_APPS = SHARED_APPS
TENANT_MODEL = "customers_as_in_django_tenants_docs.Client"
TENANT_DOMAIN_MODEL = "customers_as_in_django_tenants_docs.Domain"
CELERY_BEAT_SCHEDULER = "celery_beat_tenants_scheduler.scheduler.TenantDatabaseScheduler"
You can put on top of task's body something like that: from django.db import connection
def some_not_public_task():
if not hasattr(connection, "schema_name") or connection.schema_name == get_public_schema_name():
return
# body of all_tenants_task |
Thanks again, what's the prupose of adding |
|
@Guest007 are you tested your code i see it mixed run all tasks on all tenant I want only run each tenant task on to it is tenant |
Hi!
We make easy solution for tenants and schedules in database (like periodic tasks).
In case of:
you can't work in separate tenants with their own periodic tasks directly, without some
dispatcher task
or some separate model inpublic
tenant, likedjango-tenants-celery-beat
use.With customized DatabaseScheduler you can use celery-beat individually for each tenant as it was usual in non-tenant environment. Just remember that
django_celery_beat
must be in yourTENANT_APPS
.The text was updated successfully, but these errors were encountered: