From c05c629ca50ff60b696345bb513df15f2449b79a Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Wed, 10 Jun 2026 13:59:42 +0800 Subject: [PATCH] Resolve scheduler jobs from service aliases --- .github/workflows/sync-cloud-run-env.yml | 25 +++++++++++++++++------ tests/test_sync_cloud_run_env_workflow.sh | 6 +++++- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.github/workflows/sync-cloud-run-env.yml b/.github/workflows/sync-cloud-run-env.yml index bbfe64f..f971ba6 100644 --- a/.github/workflows/sync-cloud-run-env.yml +++ b/.github/workflows/sync-cloud-run-env.yml @@ -905,7 +905,6 @@ jobs: fi for suffix in scheduler probe-scheduler precheck-scheduler; do - job_name="${cloud_run_service}-${suffix}" case "${suffix}" in scheduler) schedule_time="${main_time}" @@ -918,12 +917,26 @@ jobs: ;; esac - current_schedule="$(gcloud scheduler jobs describe "${job_name}" \ - --project="${GCP_PROJECT_ID}" \ - --location="${scheduler_location}" \ - --format='value(schedule)' 2>/dev/null || true)" + scheduler_job_candidates=("${cloud_run_service}-${suffix}") + if [[ "${cloud_run_service}" == *-service ]]; then + scheduler_job_candidates+=("${cloud_run_service%-service}-${suffix}") + fi + + job_name="" + current_schedule="" + for candidate_job in "${scheduler_job_candidates[@]}"; do + current_schedule="$(gcloud scheduler jobs describe "${candidate_job}" \ + --project="${GCP_PROJECT_ID}" \ + --location="${scheduler_location}" \ + --format='value(schedule)' 2>/dev/null || true)" + if [ -n "${current_schedule}" ]; then + job_name="${candidate_job}" + break + fi + done + if [ -z "${current_schedule}" ]; then - echo "Cloud Scheduler job ${job_name} was not found in ${scheduler_location}; skipping schedule sync." + echo "Cloud Scheduler job for ${cloud_run_service} ${suffix} was not found in ${scheduler_location}; skipping schedule sync." continue fi diff --git a/tests/test_sync_cloud_run_env_workflow.sh b/tests/test_sync_cloud_run_env_workflow.sh index c09f245..c6a9e5c 100644 --- a/tests/test_sync_cloud_run_env_workflow.sh +++ b/tests/test_sync_cloud_run_env_workflow.sh @@ -95,7 +95,11 @@ grep -Fq 'configured_time("CLOUD_SCHEDULER_PROBE_TIME", "35 9,15")' "$workflow_f grep -Fq 'configured_time("CLOUD_SCHEDULER_PRECHECK_TIME", "45 9")' "$workflow_file" grep -Fq 'IFS=$'\''\t'\'' read -r cloud_run_service market_timezone main_time probe_time precheck_time <<< "${update}"' "$workflow_file" grep -Fq 'for suffix in scheduler probe-scheduler precheck-scheduler; do' "$workflow_file" -grep -Fq 'current_schedule="$(gcloud scheduler jobs describe "${job_name}"' "$workflow_file" +grep -Fq 'scheduler_job_candidates=("${cloud_run_service}-${suffix}")' "$workflow_file" +grep -Fq 'scheduler_job_candidates+=("${cloud_run_service%-service}-${suffix}")' "$workflow_file" +grep -Fq 'for candidate_job in "${scheduler_job_candidates[@]}"; do' "$workflow_file" +grep -Fq 'current_schedule="$(gcloud scheduler jobs describe "${candidate_job}"' "$workflow_file" +grep -Fq 'job_name="${candidate_job}"' "$workflow_file" grep -Fq 'desired_schedule="$(CURRENT_SCHEDULE="${current_schedule}" SCHEDULE_TIME="${schedule_time}" python - <<' "$workflow_file" grep -Fq 'print(" ".join([*time_fields, *current_fields[2:]]))' "$workflow_file" grep -Fq 'gcloud scheduler jobs update http "${job_name}"' "$workflow_file"