DjangoFixup
Fixup installed when using Django.
Attributes
| Attribute | Type | Description |
|---|---|---|
| app | [Celery](../../app/base/celery.md?sid=celery_app_base_celery) | The Celery application instance that this fixup is associated with and configures for Django compatibility. |
| _worker_fixup | Optional["DjangoWorkerFixup"] = None | Internal storage for the DjangoWorkerFixup instance used to manage worker-specific Django configurations. |
| _settings | Any | The Django settings object used to access project configuration during the installation process. |
| worker_fixup | [DjangoWorkerFixup](djangoworkerfixup.md?sid=celery_fixups_django_djangoworkerfixup) | Provides access to the DjangoWorkerFixup instance, initializing it with the current app if it has not been created yet. |
| _now | datetime | A cached reference to the Django timezone-aware now function used for task scheduling and logging. |
Constructor
Signature
def DjangoFixup(
app: [Celery](../../app/base/celery.md?sid=celery_app_base_celery)
)
Parameters
| Name | Type | Description |
|---|---|---|
| app | [Celery](../../app/base/celery.md?sid=celery_app_base_celery) | The Celery application instance to be associated with this fixup. |
Signature
def DjangoFixup(
app: [Celery](../../app/base/celery.md?sid=celery_app_base_celery)
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| app | [Celery](../../app/base/celery.md?sid=celery_app_base_celery) | The Celery application instance to which this fixup will be applied. |
Methods
install()
@classmethod
def install() - > [DjangoFixup](djangofixup.md?sid=celery_fixups_django_djangofixup)
Configures the environment for Django integration by adding the current directory to the system path, setting up signal handlers, and overriding the default task class.
Returns
| Type | Description |
|---|---|
[DjangoFixup](djangofixup.md?sid=celery_fixups_django_djangofixup) | The current DjangoFixup instance, allowing for method chaining. |
worker_fixup()
@classmethod
def worker_fixup() - > [DjangoWorkerFixup](djangoworkerfixup.md?sid=celery_fixups_django_djangoworkerfixup)
Retrieves or initializes the DjangoWorkerFixup instance associated with this app to manage worker-specific Django configurations.
Returns
| Type | Description |
|---|---|
[DjangoWorkerFixup](djangoworkerfixup.md?sid=celery_fixups_django_djangoworkerfixup) | The worker-specific fixup handler used to validate models and manage worker lifecycle events. |
on_import_modules()
@classmethod
def on_import_modules(
**kwargs: Any
) - > null
Signal handler that ensures Django models are validated before task modules are imported into the environment.
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | Any | Arbitrary keyword arguments passed by the import_modules signal. |
Returns
| Type | Description |
|---|---|
null |
on_worker_init()
@classmethod
def on_worker_init(
**kwargs: Any
) - > null
Signal handler that initializes the worker fixup and attaches the worker instance when the Celery worker starts.
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | Any | Keyword arguments containing the 'sender', which should be the WorkController instance. |
Returns
| Type | Description |
|---|---|
null |
now()
@classmethod
def now(
utc: bool = False
) - > datetime
Returns the current date and time, utilizing Django's timezone-aware utilities if available.
Parameters
| Name | Type | Description |
|---|---|---|
| utc | bool = False | Flag to determine whether to return the time in UTC format. |
Returns
| Type | Description |
|---|---|
datetime | The current timestamp, either in UTC or using the Django-configured timezone. |
autodiscover_tasks()
@classmethod
def autodiscover_tasks() - > List[str]
Identifies all installed Django applications to facilitate automatic task discovery.
Returns
| Type | Description |
|---|---|
List[str] | A list of strings representing the names of all registered Django app configurations. |