QuickRelease / django-tenants-celery-beat

MIT License
12 stars 9 forks source link

all_tenants attribute in Beat Schedule #33

Open premudeshi opened 9 months ago

premudeshi commented 9 months ago

Hello,

This might be a very stupid question, but what does the all_tenants attribute do when creating a beat schedule?

For example, I want to create a task that runs at 5am everyday for each tenant, but I would like the tenant to be able to change the time as they please. Would I set all_tenants to true or false?

app.conf.beat_schedule = generate_beat_schedule(
    {
        "celery.backend_cleanup": {
            "task": "celery.backend_cleanup",
            "schedule": crontab("0", "4", "*"),
            "options": {"expire_seconds": 12 * 3600},
            "tenancy_options": {
                "public": False,
                "all_tenants": True,
                "use_tenant_timezone": True,
            }
        },
    }
)
dave-v commented 8 months ago

Setting all_tenants to true will result in a periodic task being created for all tenants in their respective schemas. The configuration options will all be the same, so you can't change the time individually (apart from via the time zone setting). The generate_beat_schedule function is just a helper to save you having to duplicate a lot of the beat schedule dict. You can still manually add entries if you need more control. Check out the source for that function here.

You can also create and manage periodic tasks in the Django admin, which sounds like what you're after in this case. That allows admin users in each tenant to configure the scheduling as normal. See here. The app.conf.beat_schedule is a static definition of tasks that you know you want in advance, so it doesn't sound appropriate for your situation.