【发布时间】:2020-08-15 14:41:51
【问题描述】:
我编写了一个 HTTP 触发器,它将 ECG 数据库名称和记录号作为参数,并从云存储中读取记录,计算参数并将它们写入 Firestore。我观察到一件很奇怪的事情,代码在控制台中没有说明原因就崩溃了。这就是我在控制台中得到的全部内容:
函数执行耗时 58017 毫秒,完成状态为:'crash'`。
它通常在从 Cloud Storage 读取记录时停止。我正在使用 MIT-BIH Cloud Storage 来读取记录。
from google.cloud import storage
from flask import escape
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import numpy as np
import os
from pathlib import Path
from os import listdir
from os.path import isfile, join
from random import randint
def GCFname(request):
recordno = request.args['recordno']
database = request.args['database']
client = storage.Client()
bucket = client.get_bucket('bucket_name')
# it crashes here
record = wfdb.rdrecord(recordno, channels=[0],pb_dir='mitdb')
sig = record.p_signal[:,0]
test_qrs = processing.gqrs_detect(record.p_signal[:,0], fs=record.fs)
ann_test= wfdb.rdann(recordno, 'atr',pb_dir='mitdb')
##Calculate Parameters
cred = credentials.ApplicationDefault()
firebase_admin.initialize_app(cred, {
'projectId': 'project_name',
})
db = firestore.client()
doc_ref = db.collection('xyz').document(database).collection('abc').document(recordno)
doc_ref.set({
u'fieldname': fieldvalue
})
我已使用gcloud 进行部署,
gcloud functions deploy GCFname --runtime python37 --trigger-http --allow-unauthenticated --timeout 540s
但在使用相同的 URL 一段时间后它会起作用。这可能是什么原因?它绝对不是超时问题。
【问题讨论】:
-
这种情况是在短时间内重复触发HTTP请求时发生的。当我使用 Cloud Storage 触发功能时,也会发生同样的事情。它不会给出超时错误。会不会是脚本内部超时了?
标签: python-3.x google-cloud-firestore google-cloud-functions google-cloud-storage