From b8905eaa3a3c293a15363578127a51cbe698a9ab Mon Sep 17 00:00:00 2001 From: ZuoZuo <68836346+Mrz-sakura@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:18:59 +0800 Subject: [PATCH] deploy fix bug --- ops-scripts/tencent_operator.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/ops-scripts/tencent_operator.py b/ops-scripts/tencent_operator.py index 1571548..9171493 100755 --- a/ops-scripts/tencent_operator.py +++ b/ops-scripts/tencent_operator.py @@ -52,6 +52,12 @@ def sdk_body(resp: Any) -> dict[str, Any]: return body +def should_retry_without_output_cos(exc: TencentCloudSDKException) -> bool: + code = str(getattr(exc, "code", "") or "") + message = str(getattr(exc, "message", "") or "") + return code == "ResourceNotFound.RoleNotFound" and "TAT_QCSLinkedRoleInUploadInvocation" in message + + class CloudOperator: def __init__(self, config: dict[str, Any], service_name: str, instance_id: str, release_id: str | None) -> None: self.config = config @@ -201,9 +207,25 @@ class CloudOperator: payload["OutputCOSBucketUrl"] = self.cos_bucket_url() payload["OutputCOSKeyPrefix"] = f"{output_prefix}/{self.release_id or 'adhoc'}/{self.service_name}/{self.instance_id}" + return self._run_tat_command(payload, allow_retry_without_output_cos=bool(output_prefix)) + + def _run_tat_command(self, payload: dict[str, Any], allow_retry_without_output_cos: bool) -> str: req = tat_models.RunCommandRequest() req.from_json_string(json.dumps(payload)) - resp = self.tat.RunCommand(req) + try: + resp = self.tat.RunCommand(req) + except TencentCloudSDKException as exc: + if allow_retry_without_output_cos and should_retry_without_output_cos(exc): + log( + "TAT missing linked role TAT_QCSLinkedRoleInUploadInvocation, " + "retrying RunCommand without OutputCOSBucketUrl" + ) + retry_payload = dict(payload) + retry_payload.pop("OutputCOSBucketUrl", None) + retry_payload.pop("OutputCOSKeyPrefix", None) + return self._run_tat_command(retry_payload, allow_retry_without_output_cos=False) + raise + body = sdk_body(resp) return str(body["InvocationId"])