pg_durable icon indicating copy to clipboard operation
pg_durable copied to clipboard

fix(dsl): compute cron wait at execution time, not at df.start() time

Open Copilot opened this issue 6 months ago • 0 comments

df.wait_for_schedule() pre-computed wait_seconds at graph construction time. Any delay between df.start() and when the BGW actually runs the WAIT_SCHEDULE node caused the timer to fire early — potentially before the intended cron tick.

Approach

The orchestration must stay deterministic, so wall-clock reads must happen inside an activity. The fix captures the target timestamp (next cron tick) at DSL time for replay stability, then delegates the actual duration computation to a new activity that runs max(0, target - now()) at true execution time.

Changes

  • src/dsl.rs — store target_timestamp (RFC 3339) in node config instead of wait_seconds; cron expression is still validated eagerly
  • src/activities/compute_cron_wait.rs (new) — activity that receives target_timestamp, computes remaining seconds at execution time
  • src/orchestrations/execute_function_graph.rs — execute_wait_schedule_node schedules compute_cron_wait activity first, feeds the result into schedule_timer
  • src/registry.rs — register new activity
  • src/explain.rs — update WAIT_SCHEDULE display: WAIT '<cron>' (until <timestamp>) instead of (<secs>s)
  • src/lib.rs — update unit test to assert target_timestamp present and wait_seconds absent

Config shape change

Before:

{"cron_expr": "*/5 * * * *", "wait_seconds": 142}

After:

{"cron_expr": "*/5 * * * *", "target_timestamp": "2026-05-27T14:45:00+00:00"}

Copilot avatar May 27 '26 14:05 Copilot