Celery

Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation but supports scheduling as well. You can use Celery to run background tasks, making your applications more efficient and responsive.

Usage

from celery import shared_task
from viewflow.contrib import celery

class MyFlow(Flow):
    ...

    perform = celery.Job(this.perform_task)

    @staticmethod
    @shared_task
    def perform_task(cls, activation_ref:str) -> None:
        with celery.Job.activate(activation_ref) as activation:
            print(activation.process.message)

            # Beware of race conditions. Unlike user tasks, for
            # long-running Celery jobs, Viewflow does not set up a lock.
            activation.process.sent_at = datetime.now()
            activation.process.save(update_fields="sent_at")

            # You can also set the lock manually for a short time
            with activation.flow_class.lock(activation.process.pk):
                activation.process.refresh_from_db()
                activation.process.sent_at = datetime.now()
                activation.process.save()

See also

see the Job

See also

see the Timer