menu

Celery

PRO Only

Cookbook demo project: https://github.com/viewflow/cookbook/tree/master/celery

class viewflow.contrib.celery.Job(*args, **kwargs)

Bases: viewflow.flow.nodes.AbstractJob

Run celery a task in background

Example.

tasks.py:

from celery import shared_task
from viewflow.flow import flow_job


@shared_task
@flow_job
def sample_task(activation):
     ...

flows.py:

from viewflow.contrib import celery

class MyFlow(Flow):
    ...
    task = celery.Job(tasks.sample_task)
    ....

Note

With Django 1.8 you need to enable django-transaction-hooks

Eta(eta_callable)

Expects callable that would get the task and return datatime for task execution

To use a task with bind=True option, wrap flow_job in a method_decorator:

from django.utils.decorators import method_decorator

@shared_task(bind=True)
@method_decorator(flow_job)
def send_hello_world_request(self, activation):
    ...
class viewflow.contrib.celery.JobActivation(*args, **kwargs)

Bases: viewflow.activation.AbstractJobActivation

cancel

Cancel existing task

run_async()

Async task schedule