通过事件监听处理函数运行事件
class SFasg {
/**
* 通过事件监听,处理函数运行事件
* 函数运行事件目前包含函数运行失败,通过该结果做函数执行结果统计
*/
static void execute(FunctionContext context, FunctionMqMessage mq, Map<String, Object> arg) {
log.info(context);
log.info(arg);
String resCode = arg["resCode"] as String;
if("FAIL" == resCode){
//通知某些用户
Channel channel = Channel.Service("Xxxx")
List receiverIds = [100] //消息接收用户
String apiName = arg["apiName"] as String;
String resMsg = arg["resMsg"] as String;
String dt = DateTime.of(arg["time"] as Long).toString();
String msg = "函数"+ apiName + "运行报错,报错信息为" + resMsg + ",报错时间为" + dt;
def (error,data,errorMessage) = Fx.message.send(msg, receiverIds, channel);
if(error){
log.info(errorMessage);
}
log.info(data);
} else if("SUCCESS" == resCode){
//目前还未接入成功的消息
}
}
//debug 时候的入口方法
static void main(String[] args) {
Map map = ["resCode":"FAIL","apiName":"aaaa__c", "resMsg": "运算条件异常 Division by zero", "time": 1669301741834];
execute(null, null, map);
}
}