Exemplo n.º 1
0
 def delete_trigger(self, trigger, func_name, func_ns):
     req = models.DeleteTriggerRequest()
     req.Namespace = func_ns
     req.FunctionName = func_name
     req.TriggerName = trigger["TriggerName"]
     req.Type = str(trigger["Type"]).lower()
     req.Qualifier = "$LATEST"
     req.TriggerDesc = json.dumps(trigger["TriggerDesc"])
     self._client.DeleteTrigger(req)
Exemplo n.º 2
0
def ABTrigUpdate(AnotherFunctionName, AnotherRegion, AnotherNamespace,
                 TriggerName):
    global SecretId, SecretKey, Region
    try:
        cred = credential.Credential(SecretId, SecretKey)
        client = scf_client.ScfClient(cred, AnotherRegion)
    except TencentCloudSDKException as err:
        print(err)
    # 删除旧触发器
    try:
        req = models.DeleteTriggerRequest()
        params = '{"FunctionName":"' + AnotherFunctionName + '",'
        params += '"TriggerName":"' + TriggerName + '",'
        params += '"Namespace":"' + AnotherNamespace + '",'
        params += '"Type":"timer"}'
        req.from_json_string(params)
        resp = client.DeleteTrigger(req)
        print(resp.to_json_string())
    except TencentCloudSDKException as err:
        print(err)

    # 添加新触发器
    try:
        next_time = time.time()
        next_time += random.randint(random_time_lowerlimit,
                                    random_time_toplimit)

        req = models.CreateTriggerRequest()
        params = '{"FunctionName":"' + AnotherFunctionName + '",'
        params += '"TriggerName":"' + TriggerName + '",'
        params += '"Namespace":"' + AnotherNamespace + '",'
        params += '"Type":"timer",'
        params += '"Enable":"OPEN",'
        params += '"TriggerDesc":"' + \
            to_china_timezone_cron(next_time) + '"}'
        req.from_json_string(params)
        resp = client.CreateTrigger(req)
        print(resp.to_json_string())
    except TencentCloudSDKException as err:
        print(err)
    return