Functions that run in Custom Container runtimes rely on resources that are reserved by Function Compute. Images are cached to Function Compute to accelerate function cold starts. Function Compute allows users to view the cache status of Custom Container functions for better user experience. This topic describes the states of Custom Container functions and how the states affect function invocations.
Function states
Function Compute caches your images from Alibaba Cloud Container Registry (ACR) to accelerate function cold starts. The caching process in Function Compute is asynchronous. Resource preparation takes place asynchronously in the background regardless of whether create and update operations return synchronous results. Function states are provided to indicate the stage of resource preparation.
The states of functions in Function Compute indicate whether the functions are available for invocation. Functions that require Function Compute to reserve resources, such as a Custom Container function, can be in one of the following states:
Pending: The initial state of a function is Pending after the function is created. In this state, Function Compute attempts to reserve the required resources for the function to run. You cannot invoke a function in this state. When the corresponding image is ready, the function enters the Active state.
Active: Functions enter the Active state when Function Compute completes resource reservation. Functions in the Active state can be invoked as expected.
Failed: A function in this state fails to be invoked because an issue occurred during resource preparation.
Inactive: Functions enter the InActive state when they are idle for a long period of time. In this case, function resources, such as cached images, are released. Functions in the InActive state cannot be invoked as expected. To invoke functions in the InActive state, you can try to re-deploy or trigger the function, in which case Function Compute puts the function back into the Pending state and retries to prepare resources for the function. If the resources are prepared, the function re-enters the Active state. Otherwise, the function remains in the InActive state.
Function Compute caches images to accelerate cold starts. However, the original images cannot be missing during invocations. If the original images no longer exist, functions enter the Failed state and cannot be invoked. We recommend that you update your function at the earliest opportunity when its image is changed.
Function Compute records the tag and digest of the image version that you select when you create and update your function. If the image version is updated to another digest somewhere else, the function fails to be invoked. You must make sure that the image is not overwritten by another digest. If the image is overwritten, you must use the most recent image information to re-deploy your function.
Function states related to function updates
The LastUpdateStatus field is used to indicate the state of a function after the function is created.
InProgress: The function is being updated and Function Compute is preparing resources. Invocation requests are directed to the pre-update function code.
Successful: The function is updated. Invocation requests are directed to the updated function code.
Failed: Resources failed to be prepared for the function. Invocation requests are directed to the pre-update function code.
Invoke a function
You can call the GetFunction operation to obtain the state and image digest of a function. If you use an SDK or Serverless Devs to create or update a Custom Container function, you must call the GetFunction operation to make sure that the function is in one of the following states:
Active: For newly created functions, make sure that they are in the Active state before you invoke them. Functions in other states cannot be invoked.
Successful: For updated functions, make sure that their LastUpdateStatus values are Successful. The functions cannot be invoked if their LastUpdateStatus values are not Successful.
The following figure shows the state of a function that is being updated.
The following figure shows the state of a function that is updated.