Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions .github/workflows/sync-cloud-run-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion tests/test_sync_cloud_run_env_workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down