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
37 changes: 28 additions & 9 deletions .github/workflows/sync-cloud-run-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,8 @@ jobs:

- name: Sync Cloud Scheduler schedule
if: steps.config.outputs.env_sync_enabled == 'true'
env:
RUNTIME_TARGET_JSON: ${{ steps.strategy_requirements.outputs.runtime_target_json }}
run: |
set -euo pipefail

Expand All @@ -998,20 +1000,32 @@ jobs:
fi

mapfile -t scheduler_market_config < <(python - <<'PY'
import json
import os

raw_runtime_target = os.environ.get("RUNTIME_TARGET_JSON", "").strip()
runtime_scheduler = {}
if raw_runtime_target:
try:
runtime_target = json.loads(raw_runtime_target)
except json.JSONDecodeError:
runtime_target = {}
scheduler = runtime_target.get("scheduler") if isinstance(runtime_target, dict) else {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read scheduler plans from execution_windows

When the selected runtime target carries scheduler data through the pinned quant_platform_kit.common.runtime_target.RuntimeTarget, to_dict() serializes it under execution_windows, not scheduler. In any deployment that sets schedules via build_runtime_target(execution_windows=...), this lookup leaves runtime_scheduler empty and the workflow silently falls back to the legacy CLOUD_SCHEDULER_*_TIME values, so the new runtime-target schedule sync never applies.

Useful? React with 👍 / 👎.

if isinstance(scheduler, dict):
runtime_scheduler = scheduler

market = os.environ.get("LONGBRIDGE_MARKET", "").strip().upper()
timezone = os.environ.get("LONGBRIDGE_MARKET_TIMEZONE", "").strip()
timezone = str(runtime_scheduler.get("timezone") or os.environ.get("LONGBRIDGE_MARKET_TIMEZONE", "")).strip()
if not timezone:
timezone = "Asia/Hong_Kong" if market == "HK" else "America/New_York"

def configured_time(name: str, default: str) -> str:
return os.environ.get(name, "").strip() or default
def configured_time(key: str, name: str, default: str) -> str:
return str(runtime_scheduler.get(key) or os.environ.get(name, "").strip() or default)

print(timezone)
print(configured_time("CLOUD_SCHEDULER_MAIN_TIME", "45 15"))
print(configured_time("CLOUD_SCHEDULER_PROBE_TIME", "35 9,15"))
print(configured_time("CLOUD_SCHEDULER_PRECHECK_TIME", "45 9"))
print(configured_time("main_time", "CLOUD_SCHEDULER_MAIN_TIME", "45 15"))
print(configured_time("probe_time", "CLOUD_SCHEDULER_PROBE_TIME", "35 9,15"))
print(configured_time("precheck_time", "CLOUD_SCHEDULER_PRECHECK_TIME", "45 9"))
PY
)
market_timezone="${scheduler_market_config[0]}"
Expand Down Expand Up @@ -1061,9 +1075,14 @@ jobs:
time_fields = os.environ["SCHEDULE_TIME"].split()
if len(current_fields) != 5:
raise SystemExit(f"Cloud Scheduler schedule must have 5 fields: {os.environ['CURRENT_SCHEDULE']!r}")
if len(time_fields) != 2:
raise SystemExit(f"Cloud Scheduler time override must have 2 cron fields: {os.environ['SCHEDULE_TIME']!r}")
print(" ".join([*time_fields, *current_fields[2:]]))
if len(time_fields) == 5:
print(" ".join(time_fields))
elif len(time_fields) == 2:
print(" ".join([*time_fields, *current_fields[2:]]))
else:
raise SystemExit(
f"Cloud Scheduler override must have 2 time fields or 5 cron fields: {os.environ['SCHEDULE_TIME']!r}"
)
PY
)"

Expand Down
13 changes: 9 additions & 4 deletions tests/test_sync_cloud_run_env_workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,20 @@ grep -Fq 'gcloud_args+=(--remove-secrets "$(IFS=,; echo "${remove_secret_vars[*]
grep -Fq 'gcloud_args+=(--update-secrets "$(IFS=,; echo "${secret_pairs[*]}")")' "$workflow_file"
grep -Fq -- '--update-env-vars "^|^$(join_by_delimiter "|" "${env_pairs[@]}")"' "$workflow_file"
grep -Fq 'Sync Cloud Scheduler schedule' "$workflow_file"
grep -Fq 'RUNTIME_TARGET_JSON: ${{ steps.strategy_requirements.outputs.runtime_target_json }}' "$workflow_file"
grep -Fq 'scheduler_location="${CLOUD_SCHEDULER_LOCATION:-${CLOUD_RUN_REGION}}"' "$workflow_file"
grep -Fq 'timezone = os.environ.get("LONGBRIDGE_MARKET_TIMEZONE", "").strip()' "$workflow_file"
grep -Fq 'raw_runtime_target = os.environ.get("RUNTIME_TARGET_JSON", "").strip()' "$workflow_file"
grep -Fq 'scheduler = runtime_target.get("scheduler") if isinstance(runtime_target, dict) else {}' "$workflow_file"
grep -Fq 'timezone = str(runtime_scheduler.get("timezone") or os.environ.get("LONGBRIDGE_MARKET_TIMEZONE", "")).strip()' "$workflow_file"
grep -Fq 'timezone = "Asia/Hong_Kong" if market == "HK" else "America/New_York"' "$workflow_file"
grep -Fq 'configured_time("CLOUD_SCHEDULER_MAIN_TIME", "45 15")' "$workflow_file"
grep -Fq 'configured_time("CLOUD_SCHEDULER_PROBE_TIME", "35 9,15")' "$workflow_file"
grep -Fq 'configured_time("CLOUD_SCHEDULER_PRECHECK_TIME", "45 9")' "$workflow_file"
grep -Fq 'configured_time("main_time", "CLOUD_SCHEDULER_MAIN_TIME", "45 15")' "$workflow_file"
grep -Fq 'configured_time("probe_time", "CLOUD_SCHEDULER_PROBE_TIME", "35 9,15")' "$workflow_file"
grep -Fq 'configured_time("precheck_time", "CLOUD_SCHEDULER_PRECHECK_TIME", "45 9")' "$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 'desired_schedule="$(CURRENT_SCHEDULE="${current_schedule}" SCHEDULE_TIME="${schedule_time}" python - <<' "$workflow_file"
grep -Fq 'if len(time_fields) == 5:' "$workflow_file"
grep -Fq 'print(" ".join(time_fields))' "$workflow_file"
grep -Fq 'print(" ".join([*time_fields, *current_fields[2:]]))' "$workflow_file"
grep -Fq 'gcloud scheduler jobs update http "${job_name}"' "$workflow_file"
grep -Fq -- '--schedule="${desired_schedule}"' "$workflow_file"
Expand Down