如何在 Google appengine 中以 cron 运行单个名为“gcinfo”(在 firebase 中输出的网络爬虫)的 Go 程序?
我能够创建项目 ID 并使用 App SDK 上传 Go 程序。 cron 作业按照 cron.yaml 中的定义每 15 分钟执行一次。没有错误。但是我在日志中没有发现任何输出,并且没有写入 firebase。在对 app.yaml、gcinfo.yaml 和 cron.yaml 进行大量更改后,没有任何结果或类似错误(错误代码 204)。我现在对 yaml 文件中的设置完全感到困惑。
有人可以给我或指出这些设置的一个简单示例吗?我想每 15 分钟在应用程序引擎中将一个 Go 程序作为 cron 运行一次。
我的项目结构是:
- 包含 app.yaml 和 cron.yaml 的 myproject 文件夹
- myproject 子文件夹“hello”和 hello.yaml 以及简单的 hello.go 示例和“hello world!”
- 带有 gcinfo.yaml 和 gcinfo.go 的 myproject 子文件夹“gcinfo”(使用 firebase 输出的 webcrawler)
应用.yaml
application: myproject
version: 1
runtime: go
api_version: go1
handlers:
- url: /.*
script: _go_app
cron.yaml
cron:
- description: Ausfuehrung des tasks gcinfo
url: /gcinfo
schedule: every 15 minutes from 05:30 to 23:00
timezone: Europe/Berlin
target: gcinfo
gcinfo.yaml
application: myproject
module: gcinfo
#version: 1
runtime: go
api_version: go1
handlers:
- url: /gcinfo\.*
script: gcinfo\gcinfo.go
我的 gcinfo.go 具有以下结构
package gcinfo
import (
...
)
....
func gcinfo() {
....
}
“goapp deploy”中的此配置没有错误,appengine 每 15 分钟响应一次,持续 6 毫秒,但 go programm gcinfo 没有输出。我已经尝试将 gcinfo 设置为 main,结果相同。
请您参考如下方法:
我找到了解决方案,现在 cron 作业运行并在作业控制中写入注释。
我的项目文件夹中的 cron.yaml
cron:
- description: Ausfuehrung des tasks gcinfo
url: /gcinfo
schedule: every 15 minutes from 05:30 to 23:00
timezone: Europe/Berlin
子文件夹 gcinfo 中的 app.yaml
application: myproject
module: gcinfo
version: 1
runtime: go
api_version: go1
handlers:
- url: /gcinfo
script: _go_app
以及 gcinfo.go(gcinfo 子文件夹)中的关键变化
package gcinfo
import (
"net/http"
...
"appengine"
"appengine/urlfetch"
)
func init() {
http.HandleFunc("/gcinfo", gcinfo)
}
...
func gcinfo(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
...
}
仅编写 firebase 引擎不适用于应用引擎。我将不得不做更多的研究。






