Django-RQ:如何调用函数? [英] Django-RQ: How to call function?

查看:58
本文介绍了Django-RQ:如何调用函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将项目迁移到 Django ,并且喜欢使用 django-rq 模块.
但是,我被限制在这里:

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)

如何调用 func ?这可以是 path.file.function 之类的字符串吗?
该功能是否需要驻留在同一文件中?

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

推荐答案

创建task.py文件以包含

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

然后在您的代码中

import django_rq
from tasks import your_func

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

这篇关于Django-RQ:如何调用函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆