Interact with Procrastinate tables as Django models#

Procrastinate exposes 3 of its internal tables as Django models. You can use them to query the state of your jobs. They’re also exposed in the Django admin.

Note

We’ll do our best to ensure backwards compatibility, but we won’t always be able to do so. If you use the models directly, make sure you test your integration when upgrading Procrastinate.

from procrastinate.contrib.django.models import (
    ProcrastinateJob,
    ProcrastinateEvent,
    ProcrastinatePeriodicDefer,
)

ProcrastinateJob.objects.filter(task_name="mytask").count()

Note

The models are read-only by default. You can’t create, update or delete jobs or events through the ORM.

Reference documentation#

class procrastinate.contrib.django.models.ProcrastinateEvent(id, job, type, at)#
exception DoesNotExist#
exception MultipleObjectsReturned#
class procrastinate.contrib.django.models.ProcrastinateJob(id, queue_name, task_name, lock, args, status, scheduled_at, attempts, queueing_lock)#
exception DoesNotExist#
exception MultipleObjectsReturned#
class procrastinate.contrib.django.models.ProcrastinatePeriodicDefer(id, task_name, defer_timestamp, job, periodic_id)#
exception DoesNotExist#
exception MultipleObjectsReturned#

Making the models writable in tests#

If you need to interact with the tables in your tests, a setting is provided: PROCRASTINATE_READONLY_MODELS. If set to False, the models will be writable.

Warning

This is only intended for tests and should not be used for deferring or retrying jobs in normal operation.

Note

This is not the only testing mechanism available. See Test your code that uses Procrastinate for more features, potentially better suited for some kinds of tests and more details on this setting.