Skip to main content

DjangoFixup

Fixup installed when using Django.

Attributes

AttributeTypeDescription
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_fixupOptional["DjangoWorkerFixup"] = NoneInternal storage for the DjangoWorkerFixup instance used to manage worker-specific Django configurations.
_settingsAnyThe 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.
_nowdatetimeA 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

NameTypeDescription
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

NameTypeDescription
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

TypeDescription
[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

TypeDescription
[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

NameTypeDescription
**kwargsAnyArbitrary keyword arguments passed by the import_modules signal.

Returns

TypeDescription
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

NameTypeDescription
**kwargsAnyKeyword arguments containing the 'sender', which should be the WorkController instance.

Returns

TypeDescription
null

now()

@classmethod
def now(
utc: bool = False
) - > datetime

Returns the current date and time, utilizing Django's timezone-aware utilities if available.

Parameters

NameTypeDescription
utcbool = FalseFlag to determine whether to return the time in UTC format.

Returns

TypeDescription
datetimeThe 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

TypeDescription
List[str]A list of strings representing the names of all registered Django app configurations.