The simulated clock
Why seeded records carry past dates, and what reads the clock.
A Seed Run writes two years of history in an afternoon. Without a clock, every record would be stamped with that afternoon: a list sorted by Last Updated would show one day, and 2024's invoices would be numbered under 2026.
Cardinal gives each event a simulated instant instead. A Sales Invoice seeded for 14 May 2024 at 11:20 has creation and modified of that instant, a posting date of 14 May 2024, and a name from that year's series.
How a run moves through time
The day's tick follows the live scheduler's calendar: all, hourly and daily entries every day, weekly ones on Mondays, monthly ones on the 1st and yearly ones on 1 January. This is what expires quotations, marks invoices Overdue, turns checkins into Attendance and depreciates assets in the seeded history. A failing entry is logged on the run's Scheduler Errors and the run goes on.
What reads the clock
| Uses the simulated instant | Keeps the real time |
|---|---|
creation and modified on insert, save, submit and cancel | Job scheduling, retries and backoff |
| Versions and Comments the save writes | Sessions and auth tokens |
Naming series parts .YYYY., .YY., .MM., .DD. | Rate limits |
Today defaults, today() in expressions, Today filters | The scheduler's own ticks |
| Jobs enqueued during the event, which carry the clock in their args | Platform tables written outside the record service |
Who can set it
Only system code can set the clock, through Cardinal.DB.at/2 on a context from Cardinal.DB.as_system/1. Any other context raises, so no request and no job a user enqueued can backdate a record.
ctx = ctx |> Cardinal.DB.as_system() |> Cardinal.DB.at(~U[2024-05-14 05:50:00Z])The clock is a value on the context and in a job's arguments. No node holds it, so a job retried on another node runs under the same instant.