python - 在 Cloud Function 超时前 5 秒运行一些东西
问题描述
如果我有一个谷歌云功能,并且我以最大超时(比如说540s
)部署它,我怎么能在超时之前运行一些东西?例如,在超时前 5 秒,我想运行自定义线路?例如:
def run_something(data, context):
print('Function running...')
time.sleep(600)
if time_left <= 5_seconds:
print("Function is about to time out in 5 seconds")
解决方案
如果您想跟踪超时请求以进行进一步调查,您可以在Stackdriver Logging中过滤您的云函数的超时请求。
请注意,超时不会在 Stackdriver 中报告为错误,但是您可以设置过滤器超时日志条目。在 Google Cloud Platform Console 中,转到Stackdriver Logging并构建一个过滤器,如下所示以获取超时的请求:
resource.type="cloud_function"
resource.labels.function_name="[YOUR_FUNCTION_NAME_HERE]"
"finished with status: 'timeout'"
推荐阅读
- python - 从相似度矩阵创建 NetworkX 图
- centos - 错误'bad pad value "2m": must be positive screen distance' when using tk_messageBox on a wayland display (CentOS)
- arm - 使用 ARM M0 和 GDB 进行监控模式调试
- elasticsearch - 当我们在弹性搜索中使用倒排索引并获取包含特定单词/单词的所有文档时,在搜索中使用正向索引有什么用?
- python - 如何在 SciPy 正交距离回归 (ODR) 中使用 Lambda 函数?
- c# - C# ASP.NET Core Web API 包含在哪里
- javascript - 根据之前的下拉选择选择另一个下拉值
- python - ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()。需要帮助解决错误
- reactjs - 使用带有私有路由的上下文 API 响应登录
- fluentd - 再次创建相同文件时使用 fluentD 捕获日志