gpt4 book ai didi

python - 如何使用 Google Task Queues API 安排任务?

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:55 25 4
gpt4 key购买 nike

我想安排一个任务(即代码块)在稍后执行,其中执行的时间和日期以及其他参数作为任务负载传入。

所以我们有一个基于 Python (Django) 的 Appengine 应用程序,其中:

任务在tasks.py

中定义
@csrf_exempt
def task_myfunction(request):
if request.method == 'POST':
# Read POST parameters
# Perform task
return HttpResponse("Success")

有效载荷被添加到 views.py 中的队列中,有效载荷被 POST 到提供的 url,该 url 映射到上面定义的函数。

from google.appengine.api import taskqueue

# ..Somewhere inside a view..
taskqueue.add(queue_name='myqueue', url='/task/myfunction', params={
# Specify parameters
})

有没有办法,我可以指定执行的确切时间(带时区)以及负载数据,以便任务自动从队列中提取并在那个时刻执行。

最佳答案

您可以计算所需时间,然后在添加任务时设置倒计时eta

倒计时:

Minimum time to wait before executing this task, in seconds. Defaults to zero. Do not specify a countdown if you specified an eta.

时间:

Earliest time of task execution, in seconds. It is a datetime.datetime specifying the absolute ETA or None; this may be timezone-aware or timezone-naive. If None, defaults to now. It must be less than 30 days from current date.

https://developers.google.com/appengine/docs/python/taskqueue/tasks

正如您在上面的页面中看到的那样,似乎没有一种方法可以完全按照您的意愿进行操作:时区和特定时间。我认为你必须做那些计算。

关于python - 如何使用 Google Task Queues API 安排任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20838241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com