API | Description | Documentation |
ListAsyncEvents | This API lists the information of an asynchronously executed event. It can query the information by conditions such as `RequestId`, function name, function version, event status, and event invocation/end time. Only data within three days after event tracking is enabled can be queried. | |
GetAsyncEventStatus | This API is used to get the async event execution status based on the `RequestId`. The event status will be retained for 72 hours (after the end of the event). | GetAsyncEventStatus |
ListAsyncEvents
API frequently. To query the execution result of an async event, call the GetAsyncEventStatus
API instead.API | Description | Documentation |
TerminateAsyncEvent | This API is used to terminate an asynchronously executed event in progress according to the returned `RequestId`. The default behavior of this API is to terminate invocation. If the `GraceShutdown` parameter is set to `True`, the `SIGTERM` termination signal will be sent to the request. You can listen on the signal and customize the signal processing logic inside the function. |
/tmp
folder). If you want to use this feature, promptly write the files in the instance cache to other persistent storage media to avoid file loss after instance repossession.TerminateAsyncEvent
API and set the GraceShutdown
parameter to True
, SCF will send the termination signal SIGTERM
to the event specified in the input API parameter. You can listen on the signal and customize the processing logic after receiving the signal, including but not limited to function execution termination.SIGTERM
signal:User process exit when running
, indicating that the user process exits).SIGTERM
signal is listened on:# -*- coding: utf8 -*-import timeimport signalclass GracefulKiller:kill_now = Falsedef __init__(self):# Register signal processing functionsignal.signal(signal.SIGTERM, self.graceshutdown)def graceshutdown(self, *agrg):print("do something before shutdown.")self.kill_now = Truedef main_handler(event, context):killer = GracefulKiller()while not killer.kill_now:time.sleep(1)print(killer.kill_now)print("Graceful shutdown.")return("END")
package mainimport ("context""fmt""log""os""os/signal""syscall""time""github.com/tencentyun/scf-go-lib/cloudfunction")type DefineEvent struct {// test event defineKey1 string `json:"key1"`Key2 string `json:"key2"`}func hello(ctx context.Context, event DefineEvent) (string, error) {go graceshutdown()sleepNum := 0for {sleepNum++fmt.Println("sleep:", sleepNum)time.Sleep(time.Second)}}// Register signal processing functionfunc graceshutdown() {sigs := make(chan os.Signal, 1)signal.Notify(sigs, syscall.SIGTERM)sig := <-sigslog.Printf("receive signal %s", sig.String())//do something before shutdown.os.Exit(0)}func main() {// Make the handler available for Remote Procedure Call by Cloud Functioncloudfunction.Start(hello)}
# -*- coding: utf8 -*-from flask import Flask, requestimport timeimport signalapp = Flask(__name__)class GracefulKiller:kill_now = Falsedef __init__(self):# Register signal processing functionsignal.signal(signal.SIGTERM, self.graceshutdown)def graceshutdown(self, *agrg):print("do something before shutdown.")self.kill_now = True@app.route('/event-invoke', methods = ['POST'])def invoke():while not killer.kill_now:time.sleep(1)print(killer.kill_now)print("Graceful shutdown.")return("END")if __name__ == '__main__':killer = GracefulKiller()app.run(host='0.0.0.0', port=9000)
Was this page helpful?