Google App Engine,任务队列中的任务不会自动执行

问题描述 投票:0回答:1

我的任务被添加到任务队列,但没有自动执行。我需要单击“立即运行”按钮来运行任务,执行任务没有问题。我错过了一些配置吗?

我使用默认队列配置,标准App Engine和python 27。

from google.appengine.api import taskqueue

taskqueue.add(
        url='/inserturl',
        params={'name': 'tablename'})
python-2.7 google-app-engine task-queue
1个回答
0
投票

This documentation是您现在提到的API。这个想法是一样的:您需要为希望执行任务的时间指定参数。在这种情况下,您有不同的选项,例如countdowneta。以下是用于将任务添加到队列的方法的specific documentationtaskqueue.add

原始答案

如果您遵循此tutorial to create queues and tasks,您将看到它基于以下github repo。如果您转到创建任务的文件(create_app_engine_queue_task.py)。您应该在此处指定必须执行任务的时间。在本教程中,为了最终创建任务,他们使用以下命令:

python create_app_engine_queue_task.py --project=$PROJECT_ID --location=$LOCATION_ID --queue=$QUEUE_ID --payload=hello

但是,它缺少你想要执行它的时间,它应该是这样的

python create_app_engine_queue_task.py --project=$PROJECT_ID --location=$LOCATION_ID --queue=$QUEUE_ID --payload=hello --in_seconds=["countdown" for when the task will be executed, in seconds]

基本上,关键是在create_app_engine_queue_task.py的代码的这一部分:

if in_seconds is not None:
    # Convert "seconds from now" into an rfc3339 datetime string.
    d = datetime.datetime.utcnow() + datetime.timedelta(seconds=in_seconds)

    # Create Timestamp protobuf.
    timestamp = timestamp_pb2.Timestamp()
    timestamp.FromDatetime(d)

    # Add the timestamp to the tasks.
    task['schedule_time'] = timestamp

如果您现在创建任务并转到控制台,您将看到任务将在您指定的秒数内执行并从队列中消失。

© www.soinside.com 2019 - 2024. All rights reserved.