By Jianyi (Alibaba Cloud Serverless Senior Development Engineer)
There is a very important concept in the task system: task status and lifecycle management. The state of segmentation contributes to having a clearer understanding of what happened to the system during use to facilitate targeted operations according to business conditions.
Alibaba Cloud Function Compute (FC) Serverless Task provides a variety of queryable states and the point in time for the transition between states. Function Compute also provides the concept of task lifecycle management at the function execution level. Users can determine the execution logic when the system initializes and reclaims a series of actions to implement complete run time lifecycle management.
This article will introduce the task running status and run-time management.
After a user submits a task and receives a successful submission, the task has entered the system's lifecycle management process.
Status | Description |
Enqueued | User-triggered Task asynchronous messages have entered the internal queue and are awaiting processing. |
Dequeued | Task asynchronous messages have been dequeued from the Function Compute backend service and are waiting to be triggered. |
Running | The task is being called. |
Succeeded | Task invocation is successful. |
Failed | Task call execution failed. |
Stopped | The task call is terminated. |
Stopping | The task call is trying to stop. |
Expired | You have configured a validity period for the asynchronous invocation. The invocation is discarded and not triggered due to expiration. |
Invalid | The invocation is invalid and not triggered due to specific reasons. For example, the function is deleted. |
Retrying | The task call is being retried due to an execution error. |
The status change of a task is managed by an internal state machine, and the status is revealed to support real-time queries. The entire state transition diagram is listed below:
Figure 1
1. After a task is triggered, the task is enqueued. It changes to the Enqueued status and returns that the task is triggered successfully.
2. The task is dequeued in the backend service of Function Compute, and the task becomes Dequeued.
3. The backend checks the task configuration. If:
4. After the check, the task enters the Running state. At this time, the task has triggered the actual execution.
5. After the task is executed, it will change to the following according to the return.
6. If the user triggers Cancel during the entire status forwarding process, the task will change to the Stopping status first and try to stop the task execution. When the task is stopped, the task enters the Stopped status.
When the task status enters Running, the actual execution of the task is handed over to the Function Compute run time.
In terms of security, Function Compute will isolate different accounts by VM. Functions under the same account may run in the same VM. There is a client in the VM that manages the container to trigger the execution of the function and collect the execution results.
A user's running instance has several different states:
Figure 2
Function Compute provides interfaces for all the preceding instance status changes and supports the user-side configuration of the corresponding logic:
Figure 3
The current phase Function Compute supports stopping a single task.
When a user operation is stopped, you can configure the PreStop interface to perform a series of resource reclamation tasks before the operation is stopped. The stop operation user can use the SDK or the console to call the operation. Let’s take Go as an example. The pseudo code for stopping one-time execution is listed below:
import fc "github.com/aliyun/fc-go-sdk"
func CancelJob() {
stopInput := fc.NewStopStatefulAsyncInvocationInput("ServiceName", "FunctionName", "TaskUUID")
output, err := fcClient.StopStatefulAsyncInvocation(stopInput)
...
}
Serverless Task provides the status details of each task and persists these details in real-time. Users can query this status information in real-time according to their needs and perform corresponding operations according to the execution and business conditions.
During the running phase of a task, Function Compute provides relevant interfaces during the state transition of all instances to support user-defined logic before and after task execution. Combined with the PreStop function and the Cancel function, users can easily implement elegant operations of tasks.
Terraform for Serverless Devs – Implement Enterprise-Level Multi-Environment Deployment (Part 1)
99 posts | 7 followers
FollowAlibaba Cloud Serverless - November 10, 2022
Alibaba Cloud Native Community - April 23, 2023
Alibaba Cloud MaxCompute - December 13, 2018
Alibaba Cloud Serverless - September 29, 2022
Alibaba EMR - February 20, 2023
Alibaba Cloud Serverless - September 29, 2022
99 posts | 7 followers
FollowAlibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreElastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreVisualization, O&M-free orchestration, and Coordination of Stateful Application Scenarios
Learn MoreServerless Application Engine (SAE) is the world's first application-oriented serverless PaaS, providing a cost-effective and highly efficient one-stop application hosting solution.
Learn MoreMore Posts by Alibaba Cloud Serverless