This topic describes how to implement lifecycle hooks for function instances in a Custom Container runtime.
Lifecycle hooks
After you configure and implement a lifecycle hook for your function instances, Function Compute invokes the hook when the corresponding lifecycle event occurs. The following lifecycle hooks can be configured for a function instance: Initializer, PreFreeze, and PreStop. For more information, see Function instance lifecycle.
The following table describes the Initializer hook. The PreFreeze and PreStop hooks function similarly.
Path | Input request | Expected response |
(Optional) POST | Request body: none. Request header: common request headers. For more information, see Common request headers in Function Compute. | Response body: the return value of StatusCode
Sample code of
|
(Optional) GET |
| Response body: the return value of PreFreeze. StatusCode
|
(Optional) GET |
| Response body: the return value of PreStop. StatusCode
|
If you want to use the Initializer hook in a custom runtime, you must implement the corresponding logic with the /initialize
path and the POST
method in your HTTP server. You can refer to the sample code of initialize
in the preceding table.
If you do not configure an Initializer hook when you create a function, you do not need to implement /initialize
. In this case, even if your HTTP server implements /initialize
, the /initialize
logic in your code cannot be called and executed.