Ejemplo n.º 1
0
 def create_trigger(self, trigger, name, func_name, func_ns):
     req = models.CreateTriggerRequest()
     req.Namespace = func_ns
     req.FunctionName = func_name
     req.TriggerName = name
     req.Type = trigger.__class__.__name__.lower()
     trigger_desc = trigger.trigger_desc()
     if isinstance(trigger_desc, dict):
         trigger_desc = json.dumps(trigger_desc, separators=(',', ':'))
     req.TriggerDesc = trigger_desc
     req.Enable = getattr(trigger, "Enable", "OPEN")
     resp = self._client.CreateTrigger(req)
     click.secho(resp.to_json_string())
def create_trigger(secret_info: Dict[str, str]):
    try:
        client = get_scf_client(secret_info)

        req = models.CreateTriggerRequest()
        params = {
            "FunctionName": config.QCLOUD_FUNCTION_NAME,
            "TriggerName": "checkin-trigger",
            "Type": "timer",
            "TriggerDesc": config.QCLOUD_FUNCTION_NAME_TRIGGER,
            "Enable": "OPEN",
        }
        req.from_json_string(json.dumps(params))

        resp = client.CreateTrigger(req)
        print(resp.to_json_string())

    except TencentCloudSDKException as err:
        print(err)
Ejemplo n.º 3
0
 def create_trigger(self, trigger, name, func_name, func_ns):
     req = models.CreateTriggerRequest()
     req.Namespace = func_ns
     req.FunctionName = func_name
     req.TriggerName = name
     trigger_type = trigger.get(tsmacro.Type, "")
     req.Type = trigger_type.lower()
     proper = trigger.get(tsmacro.Properties, {})
     if trigger_type == tsmacro.TrCOS and trmacro.Bucket in proper:
         req.TriggerName = proper[trmacro.Bucket]
     if trigger_type == tsmacro.TrCMQ and trmacro.Name in proper:
         req.TriggerName = proper[trmacro.Name]
     self._fill_trigger_req_desc(req, trigger_type, proper)
     enable = proper.get(trmacro.Enable)
     if isinstance(enable, bool):
         enable = ["CLOSE", "OPEN"][int(enable)]
     req.Enable = enable
     resp = self._client.CreateTrigger(req)
     click.secho(resp.to_json_string())
Ejemplo n.º 4
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
Ejemplo n.º 5
0
 def create_trigger(self, trigger, name, func_name, func_ns):
     req = models.CreateTriggerRequest()
     req.Namespace = func_ns
     req.FunctionName = func_name
     req.TriggerName = name
     trigger_type = trigger.get(tsmacro.Type, "")
     req.Type = trigger_type.lower()
     proper = trigger.get(tsmacro.Properties, {})
     if trmacro.Message in proper:
         req.CustomArgument = proper[trmacro.Message]
     if trigger_type == tsmacro.TrCOS and trmacro.Bucket in proper:
         req.TriggerName = proper[trmacro.Bucket]
     if trigger_type in [tsmacro.TrCMQ] and trmacro.Name in proper:
         req.TriggerName = proper[trmacro.Name]
     if trigger_type in [tsmacro.TrCKafka] and trmacro.Name in proper:
         req.TriggerName = proper[trmacro.Name] + "-" + proper.get(
             trmacro.Topic)
     self._fill_trigger_req_desc(req, trigger_type, proper)
     enable = proper.get(trmacro.Enable)
     if isinstance(enable, bool):
         enable = ["CLOSE", "OPEN"][int(enable)]
     req.Enable = enable
     self._client.CreateTrigger(req)