Cron工作在Google Cloud上失败

时间:2018-03-24 18:37:18

标签: flask cron google-cloud-platform yaml scheduled-tasks

我尝试使用the cron functionality在Google Cloud上部署的服务器中添加计划任务。在部署之前,我在localhost中进行测试,所以我已经配置了一个简单的cron.yaml文件,如下所示:

#cron file
cron:

- description: Testing cron functionality
  url: /task
  schedule: every 1 minutes

一个简单的终点如下:

#myblueprint.py
#from ... import ....
from app.exceptions.sql_exceptions import (NotFoundException, InvalidValueException)
from fga.frameworks.flask.core import BeforeRequestFlow

tasks_bp = flask.Blueprint('task', __name__, url_prefix='/task')

@tasks_bp.route('', methods=['GET'])
def new_or_list():
    logging.info("++++++++++++++++++TEST CRON++++++++++++++++++")
    return flask.Response(
            response="Cron ejecutado correctamente",
            status=201
        )

所以我在localhost上运行我的服务器,然后我进入了模拟gCloud环境的Development SDK页面。在Cron Jobs部分,我的任务出现,并且还有倒计时执行它,但是当计数变为0时,任务就不会执行。

当我按下“立即运行”按钮时,只有它被执行,并且它在我的控制台中显示所需的调试消息。为什么呢?

Manual execution of the cron task due to I've clicked on the Run Now button 手动执行cron任务,因为我点击立即运行按钮

1 个答案:

答案 0 :(得分:2)

开发服务器不运行cron作业。这是一个很长时间缺失的功能。