当前位置:网站首页>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 !
边栏推荐
- 概率论与数理统计考试重点复习路线
- Ctfshow web entry code audit
- Threejs Internet of things, 3D visualization of farms (I)
- Practice | mobile end practice
- Seven join join queries of MySQL
- 直播预告 | 容器服务 ACK 弹性预测最佳实践
- All in one 1413: determine base
- 2022-2028 global and Chinese virtual data storage Market Research Report
- Raki's notes on reading paper: soft gazetteers for low resource named entity recognition
- A应用唤醒B应该快速方法
猜你喜欢
概率论与数理统计考试重点复习路线
Web开发人员应该养成的10个编程习惯
Function (error prone)
Scheduling system of kubernetes cluster
Realize the attention function of the article in the applet
C26451: arithmetic overflow: use the operator * on a 4-byte value, and then convert the result to an 8-byte value. To avoid overflow, cast the value to wide type before calling the operator * (io.2)
Sequence diagram of single sign on Certification Center
Hypothesis testing -- learning notes of Chapter 8 of probability theory and mathematical statistics
Official announcement! The third cloud native programming challenge is officially launched!
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
随机推荐
windows下Redis-cluster集群搭建
Technical tutorial: how to use easydss to push live streaming to qiniu cloud?
函數(易錯)
Mxnet imports various libcudarts * so、 libcuda*. So not found
Qt蓝牙:搜索蓝牙设备的类——QBluetoothDeviceDiscoveryAgent
首席信息官如何利用业务分析构建业务价值?
直播預告 | 容器服務 ACK 彈性預測最佳實踐
2022-2028 global and Chinese equipment as a Service Market Research Report
Uncover the seven quirky brain circuits necessary for technology leaders
Judge whether the stack order is reasonable according to the stack order
Managed service network: application architecture evolution in the cloud native Era
[phantom engine UE] the difference between running and starting, and the analysis of common problems
直播预告 | 容器服务 ACK 弹性预测最佳实践
【thingsboard】替换首页logo的方法
2022-2028 global and Chinese FPGA prototype system Market Research Report
Is "golden nine and silver ten" the best time to find a job? Not necessarily
web资源部署后navigator获取不到mediaDevices实例的解决方案(navigator.mediaDevices为undefined)
Aperçu en direct | Services de conteneurs ACK flexible Prediction Best Practices
学习MVVM笔记(一)
指针函数(基础)