Git Product home page Git Product logo

django-tenants-celery-beat's People

Contributors

ben-qr avatar dave-v avatar taliraj avatar verboserobot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-tenants-celery-beat's Issues

CELERY_RESULT_BACKEND only on public_schema

Hi,

Great add-on, thanks. I have "django_celery_results" on "shared_apps" and "tenant_apps" but for some reason all tenants results are being saved on django_celery_results_taskresult table at the public_schema and not at tenant level.

Does anyone know how to fix this? I would like to log the results by tenant.

Missing Migration

Looks like the migration 0001_initial.py was mistakenly left out. This means that it will not work unless the user runs makemigrations. This isn't typically run during CI or docker build or anything like that leaving the app broken for production. In an environment like heroku where the file system is reset whenever a dyno restart occurs, the migration will go missing.

Configuring beat_schedule for celery.backend_cleanup

Nice package. This issue adds some more information to your celery.backend_cleanup example.
There were some additional steps to get the example to work. Consider these as possible documentation additions.

First - where does the example code go: polls/polls/celery.py

Second - you have to import crontab from somewhere. Eventually you will find you should import from celery.schedules
from celery.schedules import crontab

Third - to use generate_beat_schedule you will have to import it from django_tenants_celery_beat.utils , however this import calls the project's settings environment, so you need to populate from settings before you import generate_beat_schedule. Something like this:

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polls.settings')

# must follow settings configuration as gen_beat_sch references settings
from django_tenants_celery_beat.utils import generate_beat_schedule

Finally, perhaps obvious to others (not me), but you need to have the beat_schedule config info after autodiscover_tasks()

app.autodiscover_tasks()

app.conf.beat_schedule = generate_beat_schedule(

Full example:

import os
from celery.schedules import crontab
from tenant_schemas_celery.app import CeleryApp as TenantAwareCeleryApp

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polls.settings')

# must follow settings configuration as gen_beat_sch references settings
from django_tenants_celery_beat.utils import generate_beat_schedule

app = TenantAwareCeleryApp('polls')

# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()

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": True,
                "all_tenants": True,
                "use_tenant_timezone": True,
            }
        }
    }
)


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request.tenant.schema_name))

Add tests for admin.py

Test that the admin views for public and tenant domains are behaving as expected, to avoid name leakage or ways to set up tasks to run on tenant schemas other than your own.

Public domain can:

  • see PeriodicTasks for all tenants
  • filter by tenant
  • change the tenant for any particular PeriodicTask

Tenant domains can:

  • see only their own PeriodicTasks
  • not see filters (no way to see who the other tenants are)
  • not edit the tenant for a particular PeriodicTask (field is readonly)

(In initial attempts, I had trouble getting the test database schemas to be created properly.)

Django 4: unexpected keyword argument 'display_GMT_offset'

Version 0.2.0 of django-tenants-celery-beat will generate the unexpected keyword argument 'display_GMT_offset' error when used with Django 4.1.9, and probably all versions of Django 4.

There is a solution to this error in this repo, but it was difficult to find. The purpose of this issue is to raise the visibility of the solution that can be found at the following link:

https://github.com/QuickRelease/django-tenants-celery-beat/pull/27/files

Issue with migrating

There is the problem with migrating this package ' django_tenants_celery_beat' causes that dependcies are different than after reupdating/reinstalling pip packages from Docker.

django.db.migrations.exceptions.InconsistentMigrationHistory: Migration django_tenants_celery_beat.0001_initial is applied before its dependency tenants.0003_auto_20210421_0627 on database 'default'.

A temporary solution is to copy the entire package so that the migrations remain unchanged.

How to connect this with admin panel?

@dave-v Can you provide an example how to connect this with admin panel? Also I am trying to inherit the model and add more fields to run that on user define schedule, any help would be appreciated.
Thanks

all_tenants attribute in Beat Schedule

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,
            }
        },
    }
)

Cannot add periodic_task from admin

My tenant is named Company. When I try to add a periodic_task from the admin I get the error:

DoesNotExist at /admin/django_celery_beat/periodictask/add/
Company matching query does not exist.

Thoughts on how to fix this?

Equivalency of `all_tenants` in `tenancy_options` in the Django Admin?

I'm unsure from the documentation how to achieve the following config in Period Tasks for Django admin. Previous to django-tenants-celery-beat I'd just create a task and iterate over all tenants using their tenant_context but I was wondering if I could circumvent this with django-tenants-celery-beat with database-created tasks.

"tenancy_options": {
    "public": False,
    "all_tenants": True,
    "use_tenant_timezone": True,
}

Periodic tasks on a public schema?

I want to run individual, independent schedules from tenants with PeriodicTasks from django-celery-beat.

Does this result in the periodic tasks being located in a public schema?

Requested setting LOGGING_CONFIG, but settings are not configured.

Haya,

I'm quite new with django but I'm getting:
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I've managed to clear it with adding
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')

in utils.py before
django.setup() # noqa

However, once I deploy my project to heroku it will cleare. Is there a work around to solve the error without amending package code?

Let me know if you want to see full logs

Denis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.