当前位置:网站首页>解密函数计算异步任务能力之「任务的状态及生命周期管理」
解密函数计算异步任务能力之「任务的状态及生命周期管理」
2022-07-04 18:34:00 【InfoQ】
前言
任务的状态及生命周期的管理
任务的状态管理


- 用户触发一次任务后,任务入队,变更为 Enqueued 状态,并返回触发成功;
- 任务在函数计算后端服务中出队,任务变为 Dequeued 状态;
- 后端会检查任务配置。如果
- 配置了异步消息有效期功能,并且该消息出队时间与入队时间之差已超过有效期,则任务被丢弃,变更为 Expired 状态。任务终止;
- 任务对应的函数已被删除,或创建实例出现错误,则丢弃消息,任务变更为 Invalid 状态;
- 检查后任务正式进入 Running 状态。此时任务已触发实际的执行;
- 任务执行完成后,根据返回会变更为以下几个状态:
- Retrying:用户配置了重试次数(默认为 3),且任务执行失败,这时会进入重试中状态,之后会变更为 Running 状态;
- Failed:任务执行失败,且超过了重试次数。此时会将任务状态改为 Failed;
- Succeeded:任务执行成功。
- 如果在整个状态流转过程用户触发 Cancel,则任务会先变更为 Stopping 状态,并尝试停止任务执行。当任务停止执行成功后,任务进入 Stopped 状态。
任务运行时管理及生命周期

- 创建完成 -> 执行请求阶段:支持 Initializer 功能,支持初始化实例操作。用户可以配置诸如全局变量、连接池初始化等相关操作;
- 执行中 -> 执行完成后 Pause 实例:支持 PreFreeze 接口,支持在函数 Pause 实例前执行用户侧的自定义逻辑;
- 执行中 -> 外部 cancel:函数计算会强制 Restart 用户实例,在 Restart 前支持 PreStop 接口。用户可以配置优雅停止的相关逻辑,以便支持 Cancel 时的自定义行为;
- 完成后 Pause -> 销毁实例:当一段时间没有请求后,函数计算将销毁实例。此时会调用 PreStop 接口,用户可以配置销毁容器的行为(如关闭连接池等)。

任务的停止操作
import fc "github.com/aliyun/fc-go-sdk"
func CancelJob() {
stopInput := fc.NewStopStatefulAsyncInvocationInput("ServiceName", "FunctionName", "TaskUUID")
output, err := fcClient.StopStatefulAsyncInvocation(stopInput)
...
}
总结


边栏推荐
- 安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品
- Stream流
- To sort out messy header files, I use include what you use
- Multi table operation inner join query
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- Kotlin basic data type
- Lm10 cosine wave homeopathic grid strategy
- 1002. A+b for Polynomials (25) (PAT class a)
- @transactional滥用导致数据源连接池耗尽问题
- 1003 emergency (25 points) (PAT class a)
猜你喜欢

如何使用Async-Awati异步任務處理代替BackgroundWorker?

BCG 使用之CBCGPProgressDlg进度条使用

Cbcgpprogressdlg progress bar used by BCG

Chrome开发工具:VMxxx文件是什么鬼

Detailed explanation of the binary processing function threshold() of opencv

FPGA timing constraint sharing 01_ Brief description of the four steps

"Only one trip", active recommendation and exploration of community installation and maintenance tasks

abc229 总结(区间最长连续字符 图的联通分量计数)

Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading

92. (cesium chapter) cesium building layering
随机推荐
Euler function
【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Abc229 summary (connected component count of the longest continuous character graph in the interval)
Shell programming core technology "four"
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
Siemens HMI download prompts lack of panel image solution
Socket programming demo II
Swagger突然发癫
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
Swagger suddenly went crazy
牛客小白月赛7 I 新建 Microsoft Office Word 文档
SSRS筛选器的IN运算(即包含于)用法
1007 maximum subsequence sum (25 points) (PAT class a)
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
双冒号作用运算符以及命名空间详解
92. (cesium chapter) cesium building layering
Niuke Xiaobai month race 7 e applese's super ability
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?