在flask应用程序中,我有一个函数,它获取列表列表,并将每个列表作为一行添加到excel文件中。当请求不会超时时,此函数在开发服务器上可以正常工作。在这里它被包裹在一个 try
/ except
阻止。这就是我需要在prod服务器上将其作为队列任务调用的方式。
def make_excel_file(file_title, lists_to_print):
try:
job = get_current_job()
# returns a list of lists
# the first list is the header row (titles of attributes)
# the following lists are all lists of the relevant object attributes
# as well as some joined object attributes
# (e.g. user ID, user email, drive year)
rows = wish_list_rows(lists_to_print)
wb = Workbook()
ws = wb.active
tempfile = NamedTemporaryFile()
tempfile.name = file_title
num_rows = len(rows)
_set_task_progress(0, "excel_progress") #This results in a valid notification
# so I know the function reaches at least this point
for r in rows:
ws.append(r)
wb.save(tempfile)
tempfile.seek(0)
_set_task_progress(100.0 * (num_rows/rows.index(r)), "excel_progress") #the number never
#updates, so the for loop
#must never begin
stream = tempfile.read()
response = make_response(stream)
response.headers['Content-Disposition'] = "attachment; filename={}".format(
file_title)
response.mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
except:
flash("Lists could not be exported to Excel.", "warning")
finally:
_set_task_progress(100, "excel_progress")
if response:
return response
使用本地服务器的redis cli和命令 redis-cli monitor
,可以看到以下输出:
~$ redis-cli monitor
OK
1594476959.432554 [0 [::1]:61680] "HGETALL" "rq:job:cfabaad5-b586-4aba-90b1-61addb5c9ea9"
1594476959.485371 [0 [::1]:61680] "MULTI"
1594476959.485408 [0 [::1]:61680] "LREM" "rq:queue:spur-hcd-tasks" "1" "cfabaad5-b586-4aba-90b1-61addb5c9ea9"
1594476959.487109 [0 [::1]:61680] "EXEC"
1594476976.799187 [0 [::1]:61680] "MULTI"
1594476976.801143 [0 [::1]:61680] "SADD" "rq:queues" "rq:queue:spur-hcd-tasks"
1594476976.803906 [0 [::1]:61680] "HSET" "rq:job:18be4075-8e3c-409c-a5cf-f82f3d11ba42" "status" "queued"
1594476976.803958 [0 [::1]:61680] "HMSET"
"rq:job:18be4075-8e3c-409c-a5cf-f82f3d11ba42"
"created_at" "2020-07-11T14:16:15.310435Z"
"data" "x\x9c\x94\xbd[\xcc / GIANT BYTE STRING / "
"origin" "name-of-queue"
"description" "app.tasks.make_excel_file(1, file_title='All lists', lists_to_print=[\n column_1_data, (\"column_2_data\"), column_3_data, column_5_data.\n , \n..." "enqueued_at" "2020-07-11T14:16:16.749772Z"
"started_at" "" "ended_at" ""
"timeout" "180" "status" "queued"
1594476976.841367 [0 [::1]:61680] "RPUSH" "rq:queue:spur-hcd-tasks" "18be4075-8e3c-409c-a5cf-f82f3d11ba42"
1594476976.841410 [0 [::1]:61680] "EXEC"
1594476977.433481 [0 [::1]:61680] "HGETALL" "rq:job:18be4075-8e3c-409c-a5cf-f82f3d11ba42"
我不知道该怎么解释。我还想帮助理解如何进一步调试和查看本地redis服务器上该函数中发生的事情。
编辑:我现在看到配置到应用程序的队列可能有问题。当我使用get\u current\u job()从rq获取作业时,我可以访问它。但是,应用程序队列的注册表都是空的。如果redis cli和pythonrq中的redis服务器上确实存在作业,那么什么会阻止应用程序的队列拥有作业呢?
暂无答案!
目前还没有任何答案,快来回答吧!