pg_durable
pg_durable copied to clipboard
fix(dsl): compute cron wait at execution time, not at df.start() time
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— storetarget_timestamp(RFC 3339) in node config instead ofwait_seconds; cron expression is still validated eagerlysrc/activities/compute_cron_wait.rs(new) — activity that receivestarget_timestamp, computes remaining seconds at execution timesrc/orchestrations/execute_function_graph.rs—execute_wait_schedule_nodeschedulescompute_cron_waitactivity first, feeds the result intoschedule_timersrc/registry.rs— register new activitysrc/explain.rs— update WAIT_SCHEDULE display:WAIT '<cron>' (until <timestamp>)instead of(<secs>s)src/lib.rs— update unit test to asserttarget_timestamppresent andwait_secondsabsent
Config shape change
Before:
{"cron_expr": "*/5 * * * *", "wait_seconds": 142}
After:
{"cron_expr": "*/5 * * * *", "target_timestamp": "2026-05-27T14:45:00+00:00"}