瓶路线将精氨酸传递给芹菜任务

时间:2019-06-14 05:39:44

标签: python flask celery

我正在尝试将功能参数从烧瓶路径中的函数调用传递给celery任务。我尝试了很多变量,但似乎无法弄清楚。啊。我确定我只是缺少明显的东西。这是我正在尝试的一个非常简单的任务。不疯狂我只想在后台调用一个函数并重定向到新页面。下面的代码

烧瓶路线:

@application.route("/vrops-connect", methods=["GET","POST"])
def vrops_connect():
    if request.method == "POST":
        vropshost = request.form.get('vropshost')
        vropsuser = request.form.get('vropsuser')
        vropspass = request.form.get('vropspass')
        customer_id = request.form.get('customer_id')
        # test_call()
        task = call_vrops_connect.delay(vropshost, vropsuser, vropspass, customer_id)
        return redirect('get-json')

芹菜任务:

@celery.task(name='call.vrops.connect')
def call_vrops_connect(vropshost, vropsuser, vropspass, customer_id):
    test_connect = 'call vrops connect was called '
    with open('test_connect.log', 'a') as j:
        j.write(test_connect)
    vhost = vropshost
    vuser = vropsuser
    vpass = vropspass
    cust_id = customer_id
    pull_data_from_vrops(vhost, vuser, vpass, cust_id)

我有一个test_call(),没有任何参数可以很好地工作。当我通过args时,什么都不会被调用。我有一种创建测试日志的方法。

我尝试了延迟和apply_async的几种变体。

编辑:

这些是到目前为止我尝试过的一些变化。

test_call() # This works
call_vrops_connect.delay(vropshost, vropsuser, vropspass, customer_id) # This doesn't
task = call_vrops_connect.delay(vropshost, vropsuser, vropspass, customer_id) # This doesn't        
call_vrops_connect.apply_async(args=[vropshost, vropsuser, vropspass, customer_id]) # This doesn't
call_vrops_connect.apply_async(kwargs={'vropshost': vropshost, 'vropsuser': vropsuser, 'vropspass': vropspass, 'customer_id': customer_id}) # This doesn't
task = call_vrops_connect.apply_async(args=[vropshost, vropsuser, vropspass, customer_id]) # This doesn't
task = call_vrops_connect.apply_async(kwargs={'vropshost': vropshost, 'vropsuser': vropsuser, 'vropspass': vropspass, 'customer_id': customer_id}) # This doesn't

0 个答案:

没有答案