dongxinm279890 2015-01-08 15:40
浏览 73
已采纳

在Google App Engine上执行Go程序(网络搜寻器)作为Cron作业

How can I run a single Go program namend "gcinfo" (webcrawler with output in firebase) as a cron in Google appengine?

I was able to create a projekt-ID and upload the Go programm with the App SDK. The cron job was executed as defined in the cron.yaml every 15 minutes. There was no error. But i find no output in the log and firebase ist not written. After lots of changes in the app.yaml, gcinfo.yaml and cron.yaml with no result or Errors like (Error code 204). I am now totally confused about the settings in the yaml-files.

Can someone give or point me to a simple example of these settings? I want to run a single Go program as a cron in the app engine every 15 minutes.

My projekt structur is:

  • myproject folder with app.yaml and cron.yaml
  • myproject subfolder "hello" with hello.yaml and the simple hello.go example with "hello world!"
  • myproject subfolder "gcinfo" with gcinfo.yaml and gcinfo.go (go webcrawler with firebase-output)"

app.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

My gcinfo.go has the following structure

package gcinfo

import (
...
)

....

func gcinfo() {
....
}

There are no errors with this configuration in the "goapp deploy" and the appengine reacts every 15 minutes for 6ms, but there is no output for the go programm gcinfo. I have already tryed to make gcinfo to main with same result.

  • 写回答

1条回答 默认 最新

  • doudeng8691 2015-01-14 18:30
    关注

    I have found a solution and now the cron job runs and writes comments in the Job Control.

    cron.yaml in myproject folder

    cron:
    - description: Ausfuehrung des tasks gcinfo
    url: /gcinfo
    schedule: every 15 minutes from 05:30 to 23:00
    timezone: Europe/Berlin
    

    app.yaml in the subfolder gcinfo

    application: myproject
    module: gcinfo
    version: 1
    runtime: go
    api_version: go1
    
    handlers:
    - url: /gcinfo
      script: _go_app 
    

    and the key changes in gcinfo.go (gcinfo subfolder)

    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)
    ...
    }
    

    Only writing firebase engine does not work with the appengine. I'll have to do more research.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog