当前位置:网站首页>解密函数计算异步任务能力之「任务的状态及生命周期管理」
解密函数计算异步任务能力之「任务的状态及生命周期管理」
2022-07-06 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)
...
}
总结
边栏推荐
- Redis configuration class redisconfig
- How to use strings as speed templates- How to use String as Velocity Template?
- ROS learning (22) TF transformation
- freeswitch拨打分机号源代码跟踪
- ROS学习(24)plugin插件
- 红外相机:巨哥红外MAG32产品介绍
- Analyze "C language" [advanced] paid knowledge [II]
- The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
- 百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
- Long press the button to execute the function
猜你喜欢

ROS学习(25)rviz plugin插件

微服务架构介绍

STM32F4---通用定时器更新中断

ROS学习(十九)机器人SLAM功能包——cartographer

454 Baidu Mianjing 1

Ros Learning (23) Action Communication Mechanism

@Before, @after, @around, @afterreturning execution sequence

Gin introduction practice

2022/0524/bookstrap

Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter
随机推荐
ZOJ problem set – 2563 long dominoes [e.g. pressure DP]
Livox激光雷达硬件时间同步---PPS方法
Basic introduction and use of dvajs
Treadpoolconfig thread pool configuration in real projects
激光雷达:Ouster OS产品介绍及使用方法
Ros Learning (23) Action Communication Mechanism
How can I code for 8 hours without getting tired.
Centros 8 installation MySQL Error: The gpg Keys listed for the "MySQL 8.0 Community Server" repository are already ins
C language [23] classic interview questions [Part 2]
Stm32f4 --- general timer update interrupt
Domestic images of various languages, software and systems. It is enough to collect this warehouse: Thanks mirror
npm install 编译时报“Cannot read properties of null (reading ‘pickAlgorithm‘)“
BigDecimal 的正确使用方式
STM32F4---通用定时器更新中断
Date processing tool class dateutils (tool class 1)
Shell script quickly counts the number of lines of project code
Flir Blackfly S USB3 工业相机:白平衡设置方法
ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
MySQL's most basic select statement
Flir Blackfly S工业相机:颜色校正讲解及配置与代码设置方法