Google 计算引擎示例
Google compute engine example
我正在尝试给定的示例 here。它使用 google 应用引擎、云引擎
和 pub/sub 服务在 GCE 上执行 cron 任务。这相当简单
理解和执行。但是我尝试更换 logger_sample_task.py
用我自己的代码编码(在下面给出)。它所做的只是将一个字符串记录到日志文件中。 注意:脚本 运行s 在 Google 计算引擎
import logging
logging.basicConfig(filename='testlog.log', level=logging.INFO)
logging.info('Hope this works')
然而,当我检查 cron 任务是否为 运行 时设置后,cron 服务有
状态失败。
我完全按照给定的所有步骤进行了操作(有和没有
我的自定义脚本),但它仍然说 cron 作业失败。任何原因或方法找出
失败的原因?
App 引擎在其日志中有此错误:
https://pubsub.googleapis.com/v1beta2/projects/dummy-project-1082/topics/test:publish?alt=json
returned "One or more messages in the publish request is empty. Each
message must contain either non-empty data, or at least one
attribute.">
更新:按照this post
中的建议消除了应用引擎错误
已修复。
问题出在这个 script 中。特别是在声明函数的行中的 publish_to_topic
函数中:
def publish_to_topic(topic, msg='', create=True):
这会导致应用向 gce 应用正在侦听的 pub/sub 主题发布空消息(应用引擎在我上面发布的错误消息中抱怨过)
只需将 msg=''
更改为 msg='test'
。并且 cron 作业成功。
我正在尝试给定的示例 here。它使用 google 应用引擎、云引擎 和 pub/sub 服务在 GCE 上执行 cron 任务。这相当简单 理解和执行。但是我尝试更换 logger_sample_task.py 用我自己的代码编码(在下面给出)。它所做的只是将一个字符串记录到日志文件中。 注意:脚本 运行s 在 Google 计算引擎
import logging
logging.basicConfig(filename='testlog.log', level=logging.INFO)
logging.info('Hope this works')
然而,当我检查 cron 任务是否为 运行 时设置后,cron 服务有
状态失败。
我完全按照给定的所有步骤进行了操作(有和没有 我的自定义脚本),但它仍然说 cron 作业失败。任何原因或方法找出 失败的原因?
App 引擎在其日志中有此错误:
https://pubsub.googleapis.com/v1beta2/projects/dummy-project-1082/topics/test:publish?alt=json returned "One or more messages in the publish request is empty. Each message must contain either non-empty data, or at least one attribute.">
更新:按照this post
中的建议消除了应用引擎错误已修复。
问题出在这个 script 中。特别是在声明函数的行中的 publish_to_topic
函数中:
def publish_to_topic(topic, msg='', create=True):
这会导致应用向 gce 应用正在侦听的 pub/sub 主题发布空消息(应用引擎在我上面发布的错误消息中抱怨过)
只需将 msg=''
更改为 msg='test'
。并且 cron 作业成功。