Jan
Jan

Reputation: 43199

Django-RQ: How to call function?

I am migrating a project to Django and like to use the django-rq module.
However, I am stuck at what to put here:

import django_rq
queue = django_rq.get_queue('high')
queue.enqueue(func, foo, bar=baz)

How to call func ? Can this be a string like path.file.function ?
Does the function need to reside in the same file?

Upvotes: 2

Views: 1857

Answers (1)

dmitryro
dmitryro

Reputation: 3516

Create tasks.py file to include

from django_rq import job     

@job("high", timeout=600) # timeout is optional
def your_func(*args, **kwargs):
     pass # do some logic

and then in your code

import django_rq
from tasks import your_func

queue = django_rq.get_queue('high')
queue.enqueue(your_func, foo, bar=baz)

Upvotes: 3

Related Questions