当前位置:网站首页>Decryption function calculates "task state and lifecycle management" of asynchronous task capability
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
2022-07-05 04:28:00 【Alibaba cloud native】
author : Gradually meaning
Preface
There is a very important concept in the task system , That is, the state of the task and the life management cycle . Its essence is the life cycle management of tasks . The subdivided state helps to understand what happened to the system more clearly when using , It is convenient to operate according to the business situation . Function calculation Serverless Task Provides a variety of queriable statuses , And provide the time point of transition between States . At the level of function execution , Functional computing also provides the concept of task lifecycle management , Users can decide when the system initializes the task instance according to their needs 、 The execution logic of a series of actions such as recycling , Achieve complete runtime lifecycle management . This paper will introduce the two aspects of task running state and runtime management .
Management of task status and life cycle
Task status management
When the user submits the task and receives the return of successful submission , The task has entered the management process of the system for its life cycle . The state change of a task is managed by an internal state machine , It also supports real-time query of external disclosure status . The whole state transition diagram is shown below :
chart 1
- After the user triggers a task , Task in the team , Changed to: Enqueued state , And return trigger success ;
- The task is queued in the back-end service of function calculation , The task becomes Dequeued state ;
- The backend will check the task configuration . If
- The asynchronous message validity function is configured , And the difference between the time of leaving the team and the time of joining the team has exceeded the validity period , Then the task is discarded , Changed to: Expired state . Task to terminate ;
- The function corresponding to the task has been deleted , Or there is an error creating the instance , Then discard the message , The task is changed to Invalid state ;
- After the inspection, the task officially enters Running state . At this time, the task has triggered the actual execution ;
- When the task is completed , According to the return, it will change to the following states :
- Retrying: The user has configured the number of retries ( The default is 3), And the task execution failed , At this time, it will enter the retry state , Then it will be changed to Running state ;
- Failed: Task execution failed , And the number of retries has exceeded . The task status will be changed to Failed;
- Succeeded: The task was executed successfully .
- If the user triggers during the whole state flow Cancel, Then the task will be changed to Stopping state , And try to stop the task . When the task stops successfully , Mission entry Stopped state .
Task runtime management and life cycle
When the task status enters Running after , The actual execution of the task has been handed over to the runtime of function calculation . In terms of security , Function calculation will follow VM Isolate different accounts , Functions under the same account may run in the same VM in .VM There is a client in charge of managing containers , To actually trigger the execution of the function , And collect the execution results .
The running instance of the user has several different states :
chart 2
Function calculation provides interfaces for the process of state changes of all the above instances , Support user side configuration of corresponding logic .
- The creation is complete -> Execute request phase : Support Initializer function , Support initializing instance operations . Users can configure such as global variables 、 Connection pool initialization and other related operations ;
- In execution -> After execution Pause example : Support PreFreeze Interface , Support in function Pause Execute user-defined logic before the instance ;
- In execution -> external cancel: Function evaluation will force Restart User instance , stay Restart Pre support PreStop Interface . The user can configure the logic of graceful stop , To support Cancel Custom behavior when ;
- After completion Pause -> Destroy instance : When there is no request for a period of time , Function calculation will destroy the instance . This will call PreStop Interface , Users can configure the behavior of destroying containers ( Such as closing the connection pool ).
chart 3
Stop the task
At present, function calculation supports the operation of stopping a single task . When the user operation stops , The supporting configuration PreStop Interface , Carry out a series of resource recovery work before stopping . Stop the operation, and the user can use SDK Or console . With Go Language as an example , The pseudocode that stops execution once is shown below :
import fc "github.com/aliyun/fc-go-sdk"
func CancelJob() {
stopInput := fc.NewStopStatefulAsyncInvocationInput("ServiceName", "FunctionName", "TaskUUID")
output, err := fcClient.StopStatefulAsyncInvocation(stopInput)
...
}
summary
Serverless Task Provides status details for each task , These details will be persisted in real time . Users can query these status information in real time according to their needs , And carry out corresponding operations according to the implementation and business conditions . In the running phase of the task , Function calculation provides relevant interfaces in the process of state transition of all instances , Support user-defined logic before and after task execution . combination PreStop Function and Cancel Stop task function , Users can easily realize the elegant operation of tasks .
Looking back
Function calculation asynchronous task capability introduction - Task trigger de duplication
1 minute Serverless Build real websites at top speed
Use Serverless 1 Minutes to easily build your first personal website !
Free Quota , Pick up ! Xiaobai can also set up a station at a high speed : No need to consider the server and website source code , We provide you with free computing resources , Operation and maintenance management server . Complete the scene experience during the activity , I have the chance to get Tmall supermarket 10 Yuan voucher .( Suggest pc The experience )
Activity time : 2022 year 6 month 20 Japan -7 month 1 Japan ( Collect during working days )
Q & a group : Nail search “44700570”
Experience address : Click to read the original text or Scan QR code
Click on here , Direct experience !
边栏推荐
- mxnet导入报各种libcudart*.so、 libcuda*.so找不到
- Official announcement! The third cloud native programming challenge is officially launched!
- Web开发人员应该养成的10个编程习惯
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- Study notes 7
- TPG x AIDU | AI leading talent recruitment plan in progress!
- A應用喚醒B應該快速方法
- This is an age of uncertainty
- 小程序中实现文章的关注功能
- Fuel consumption calculator
猜你喜欢
防护电路中的元器件
【虚幻引擎UE】实现UE5像素流部署仅需六步操作少走弯路!(4.26和4.27原理类似)
Function (error prone)
【UNIAPP】系统热更新实现思路
Seven join join queries of MySQL
指针函数(基础)
Qt蓝牙:搜索蓝牙设备的类——QBluetoothDeviceDiscoveryAgent
Web开发人员应该养成的10个编程习惯
User behavior collection platform
Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
随机推荐
[Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
可观测|时序数据降采样在Prometheus实践复盘
A solution to the problem that variables cannot change dynamically when debugging in keil5
level18
TPG x AIDU|AI领军人才招募计划进行中!
Study notes 7
Interview related high-frequency algorithm test site 3
Is "golden nine and silver ten" the best time to find a job? Not necessarily
PHP reads the INI file and writes the modified content
SPI read / write flash principle + complete code
蛇形矩阵
mysql的七种join连接查询
Ctfshow 2022 Spring Festival welcome (detailed commentary)
Threejs Internet of things, 3D visualization of farm (III) model display, track controller setting, model moving along the route, model adding frame, custom style display label, click the model to obt
Kwai, Tiktok, video number, battle content payment
包 类 包的作用域
Invalid bound statement (not found) in idea -- problem solving
Common features of ES6
取余操作是一个哈希函数
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法