Celery integration for django-tenant-schemas and django-tenants
Project description
tenant-schemas-celery
=====================
[![Build Status](https://travis-ci.org/maciej-gol/tenant-schemas-celery.svg?branch=master)](https://travis-ci.org/maciej-gol/tenant-schemas-celery)
Celery application implementation that allows celery tasks to cooperate with
multi-tenancy provided by [django-tenant-schemas](https://github.com/bernardopires/django-tenant-schemas) and
[django-tenants](https://github.com/tomturner/django-tenants) packages.
Installation
------------
```bash
$ pip install tenant-schemas-celery
$ pip install django-tenants
```
Usage
-----
* Define a celery app using given `CeleryApp` class.
```python
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
from django.conf import settings
from tenant_schemas_celery.app import CeleryApp
app = CeleryApp()
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
```
This assumes a fresh Celery 3.1.13 application. For previous versions, the key is to create a new `CeleryApp` instance that will be used to access task decorator from.
* Replace your `@task` decorator with `@app.task`
```python
from django.db import connection
from myproject.celery import app
@app.task
def my_task():
print connection.schema_name
```
* Run celery worker (`myproject.celery` is where you've defined the `app` variable)
```bash
$ celery worker -A myproject.celery
```
* Post registered task. The schema name will get automatically added to the task's arguments.
```python
from myproject.tasks import my_task
my_task.delay()
```
The `TenantTask` class transparently inserts current connection's schema into
the task's kwargs. The schema name is then popped from the task's kwargs in
`task_prerun` signal handler, and the connection's schema is changed
accordingly.
=====================
[![Build Status](https://travis-ci.org/maciej-gol/tenant-schemas-celery.svg?branch=master)](https://travis-ci.org/maciej-gol/tenant-schemas-celery)
Celery application implementation that allows celery tasks to cooperate with
multi-tenancy provided by [django-tenant-schemas](https://github.com/bernardopires/django-tenant-schemas) and
[django-tenants](https://github.com/tomturner/django-tenants) packages.
Installation
------------
```bash
$ pip install tenant-schemas-celery
$ pip install django-tenants
```
Usage
-----
* Define a celery app using given `CeleryApp` class.
```python
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
from django.conf import settings
from tenant_schemas_celery.app import CeleryApp
app = CeleryApp()
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
```
This assumes a fresh Celery 3.1.13 application. For previous versions, the key is to create a new `CeleryApp` instance that will be used to access task decorator from.
* Replace your `@task` decorator with `@app.task`
```python
from django.db import connection
from myproject.celery import app
@app.task
def my_task():
print connection.schema_name
```
* Run celery worker (`myproject.celery` is where you've defined the `app` variable)
```bash
$ celery worker -A myproject.celery
```
* Post registered task. The schema name will get automatically added to the task's arguments.
```python
from myproject.tasks import my_task
my_task.delay()
```
The `TenantTask` class transparently inserts current connection's schema into
the task's kwargs. The schema name is then popped from the task's kwargs in
`task_prerun` signal handler, and the connection's schema is changed
accordingly.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for tenant-schemas-celery-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67f90e32777b9b7a9b384a4a0415d03574b998ffbf400871825f528a321a9447 |
|
MD5 | fb56ca3b307cf46937b52e55a5f56476 |
|
BLAKE2b-256 | ca10bb1d8ecd374494bb9e016768000611fa2853e29fd9726465f2da76710518 |