我有一份作業,每晚運行計算并將結果存盤在 sqlite 檔案谷歌存盤中。當我手動運行時,計劃任務總是成功。當 cron (Google Cloud Scheduler) 運行它時,它總是失敗。日志沒有給出有意義的錯誤訊息。502 錯誤代碼。啟動一個無關緊要的新實體。我將 cron.yaml 設定為重試 2 次。但所有處決都失敗了。
我的 cron.yaml
- description: "PAPER GO calc from alpaca to /tmp/entries.sqlite"
target: default
url: /calcentriesindb
schedule: every sun,mon,tue,wed,thu 20:00
timezone: America/New_York
retry_parameters:
job_retry_limit: 2
min_backoff_seconds: 30
最上面的日志條目是手動執行。以下 3 次是 cron 嘗試。
從 502 錯誤完成日志條目
{
"protoPayload": {
"@type": "type.googleapis.com/google.appengine.logging.v1.RequestLog",
"appId": "s~wc2022-356423",
"versionId": "20220730t143529",
"requestId": "62eb0c5d00ff0bb76d8eabcbfc0001737e7763323032322d3335363432330001323032323037333074313433353239000100",
"ip": "0.1.0.2",
"startTime": "2022-08-04T00:01:33.767986Z",
"endTime": "2022-08-04T00:01:34.565759Z",
"latency": "0.797773s",
"method": "GET",
"resource": "/calcentriesindb",
"httpVersion": "HTTP/1.1",
"status": 502,
"responseSize": "288",
"userAgent": "AppEngine-Google; ( http://code.google.com/appengine)",
"urlMapEntry": "auto",
"host": "default.wc2022-356423.uc.r.appspot.com",
"cost": 3.2186e-8,
"taskQueueName": "__cron",
"taskName": "05697141537686660811",
"wasLoadingRequest": true,
"instanceIndex": -1,
"finished": true,
"instanceId": "00c61b117c3c5fa64d13a841d4e8db781b8d5f07b01c3875537cbb754a073373efdb153e58e5d70a725960c452ea04b253df39c0c286628e0dec6d",
"line": [
{
"time": "2022-08-04T00:01:34.565621Z",
"severity": "INFO",
"logMessage": "This request caused a new process to be started for your application, and thus caused your application code to be loaded for the first time. This request may thus take longer and use more CPU than a typical request for your application."
}
],
"appEngineRelease": "1.9.71",
"traceId": "115ab8ca6be26417bc63bb90824dbd71",
"first": true,
"traceSampled": true,
"spanId": "1960824541831512114"
},
"insertId": "62eb0c5e0008a2c1355ad083",
"httpRequest": {
"status": 502
},
"resource": {
"type": "gae_app",
"labels": {
"project_id": "wc2022-356423",
"zone": "us16",
"module_id": "default",
"version_id": "20220730t143529"
}
},
"timestamp": "2022-08-04T00:01:33.767986Z",
"severity": "INFO",
"labels": {
"clone_id": "00c61b117c3c5fa64d13a841d4e8db781b8d5f07b01c3875537cbb754a073373efdb153e58e5d70a725960c452ea04b253df39c0c286628e0dec6d"
},
"logName": "projects/wc2022-356423/logs/appengine.googleapis.com/request_log",
"operation": {
"id": "62eb0c5d00ff0bb76d8eabcbfc0001737e7763323032322d3335363432330001323032323037333074313433353239000100",
"producer": "appengine.googleapis.com/request_id",
"first": true,
"last": true
},
"trace": "projects/wc2022-356423/traces/115ab8ca6be26417bc63bb90824dbd71",
"receiveTimestamp": "2022-08-04T00:01:34.572846740Z",
"spanId": "1960824541831512114",
"traceSampled": true
}
從處理程式呼叫的關鍵函式:
func CalcEntriesInDb() (interface{}, error) {
symbols, err := getTradableSymbols()
if err != nil {
log.Fatal("getTradableSymbols failed.", err)
}
log.Println(len(symbols), "symbols to scan.")
createPath(c.EntryDbPath) // forces a specific path to exist including creation of folders.
runList := GetRunList(c.RefDbPath)
////loadHistory because of weekends and holidays lets gather more than 13 days to get enough trail for minlow
rowcount, err := loadHistory(20, symbols, c.EntryDbPath)
if err != nil {
log.Fatal(err)
}
log.Println(`Running `, len(runList), `sql scripts.`)
runSqlScripts(runList, c.EntryDbPath)
err = gcsUp(c.EntryDbPath)
sendEmail("Entries Calculated", PrintTableHTML(c.EntryDbPath, "entry"), c.EntryDbPath)
return rowcount, err
}
這是我的 indexHandler 的摘錄
func indexHandler(w http.ResponseWriter, r *http.Request) {
spew.Dump(r.URL.Query())
params := r.URL.Query()
var apikey string
log.Println("X-Appengine-Cron", r.Header["X-Appengine-Cron"])
//log.Println(params["marina"])
if len(params["marina"]) == 1 {
apikey = params["marina"][0]
}
if len(r.Header["X-Appengine-Cron"]) > 0 || apikey == c.Apikey {
log.Println("Key or Param passed.")
} else {
http.NotFound(w, r)
return
}
//spew.Dump(r.URL.Path)
switch r.URL.Path {
case "/calcentriesindb":
resp, err := CalcEntriesInDb()
if err != nil {
_, err = fmt.Fprint(w, err)
} else {
_, err = spew.Fprint(w, resp)
}
uj5u.com熱心網友回復:
我曾經遇到過類似的問題,但我不記得狀態碼是否為 502。過去發生的事情是 - 當我通過 Cron UI 運行作業時,它會報告“失敗”狀態,但如果我手動呼叫該作業,它將成功完成。
后來我發現問題是 - cron 作業旨在回傳 200 - 299 之間的狀態(請參閱檔案)。我的 cron 作業呼叫的路由將任務添加到佇列,然后重定向到我的主頁(這意味著它回傳 301)。我將其更改為回傳一個固定的文本(例如“完成”),它是一個 200 狀態并解決了問題。
uj5u.com熱心網友回復:
我終于讓 gae cron 作業了。我創建了一個包含 apikey 的 cron 條目。這是一種解決方法,而不是修復方法。我沒有安排/calcentriesindb
我安排/calcentriesindb?marina=apikey. 我撰寫的代碼在從應用引擎 cron 執行時不需要 api 密鑰。那好吧。應用引擎處理計劃請求的方式肯定仍然存在問題。此外,如果您沒有在其他評論中看到 - 使用 curl 從完全不同的服務器調度請求可以完美地作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/507754.html
標籤:Google Cloud Collective 谷歌应用引擎 cron 谷歌云调度程序
上一篇:在GAE上找不到使用自定義域的SSL證書的DNS記錄
下一篇:設定或配置云端點中的端點超時
