Django-RQ: How to call function?

无人久伴 提交于 2019-12-07 19:14:14

问题


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?


回答1:


Create tasks.py file to include

from django_rq import job     

@job("high", timeout=600) # timeout is optional
def your_func():
     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)


来源:https://stackoverflow.com/questions/38106696/django-rq-how-to-call-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!