Running it
Time and Attendance runs inside the same program as Connect. It uses the same database. This page shows how to turn it on and how to send a tenant its punches. It also shows what happens to a punch and to a ledger after that.
Time and Attendance is one more client of Connect. It receives punch events through a sink, the way any outside system would. It reads only the public event contract.
Turning it on
Section titled “Turning it on”Start an instance with HOURADVANTAGE_ATTEND=on to run Time and Attendance on it. These values also turn it on: true, yes and 1. These values leave it off: unset, empty, off, false, no and 0. Any other value stops the program with an error.
HOURADVANTAGE_ATTEND=on hourd runThe variable only turns the engine on. It does not say which customers the engine keeps time for. That is data in the database, and it is the same for every instance. Those customers are its tenants. You create each one through the API or with hourctl attend tenants create.
An instance with the engine on does these things:
- It brings the attendance schema up to date in Connect’s database. The schema has a history of its own, called
attendance_schema_history. - It takes punches from time sinks. It also takes them at
POST /api/attendance/tenants/{tenant}/deliveries. - It works out ledgers for every active tenant. Every other instance that runs the engine does the same.
- It answers the attendance API at
/api/attendance/.... - It delivers the engine’s events to its own sinks. See events and sinks.
If the database cannot be reached for the schema update, the instance tries again every 1 to 30 seconds. It logs each try, as it does for Connect’s schema. It is not ready in the meantime. A schema it cannot use stops the start. An example is a change from a newer version that this version has not said it may run after.
The standard steps are built in. Give every instance that should work out ledgers the same value. An instance without it runs only Connect. It answers /api/attendance/... with 503.
The time sink
Section titled “The time sink”Punches reach a tenant in one of two ways. Both prove they may feed the tenant with one of the tenant’s delivery keys.
- A time sink is a Connect sink of type
in_process. It hands its events to the engine in the same program. It carries a delivery key as itssecret. - A signed post goes to
POST /api/attendance/tenants/{tenant}/deliveries. It comes from a webhook sink of another install, or from any other system. It is signed with a delivery key.
Each time sink names the tenant its punches are for. Create the tenant, issue a key, then make the sink:
hourctl attend tenants create acme --name "Acme Manufacturing"export KEY=$(hourctl -t acme attend delivery-keys create --label "time sink")hourctl sink add time --receiver attendance --receiver-tenant acme --secret-env KEY --event punchhourctl endpoint set office --sink timeOr in a setup file:
[[sink]]id = "time"type = "in_process"receiver = "attendance"tenant = "acme"secret_env = "ACME_DELIVERY_KEY" # holds the delivery keyevents = ["punch"]One sink feeds one tenant. To feed several tenants, make several sinks. A sink that names no tenant has its deliveries refused.
A sink in a Connect tenant’s setup is sent that tenant’s events. A sink at the install level (hourctl --install sink add) is sent every Connect tenant’s events. So an install that keeps time for more than one customer gives each customer its own sink. You put that sink in the setup of the Connect tenant whose clocks it reads. See tenants.
A sink can speak for a system. You set that with --system attendance, or with system = "attendance" in a setup file. Such a sink is sent only the punches routed to that system. Each punch carries the person’s id there, as person_id. A sink that names no system is sent every punch.
An in_process sink takes no url. Otherwise it behaves like any other sink. It is sent its events in stored order, at least once. A problem holds up only that sink.
The engine refuses a sink’s deliveries in two cases. The first is when the sink’s tenant does not exist or is suspended. The second is when its key is not one of the tenant’s. The engine says why in the sink’s status. The sink waits and falls behind, while every other sink goes on. See a refused sink. The same happens when the instance delivering to the sink does not run the engine.
From punch event to punch fact
Section titled “From punch event to punch fact”The engine reads each punch event by the public event contract alone. A punch fact is the engine’s own record of one punch. This table shows where each part of it comes from.
| Punch fact | From the event |
|---|---|
| Id | The event’s id. The same record uploaded again is the same fact. |
| Instant | data.time. This is the device’s local time with its offset. |
| Kind | data.state_name. check_in and overtime_in are in. check_out and overtime_out are out. meal_out and meal_in start and end lunch. break_out and break_in start and end a break. Anything else, or none, is unknown. Then pairing works out the direction. |
| Values | Each code of the route the punch came by (data.route.codes) becomes a value of the same name. If the person entered a data.work_code, it becomes the value work_code. |
| Person | The event’s person_id, or the person_id of the punch’s route (data.route). The event’s person_id is the id the sink’s system knows the person by. See external ids. If there is neither, the punch belongs to an unlinked person. That person is keyed by Connect’s id of the person in their sync group. The key is <group>~<person> for the default Connect tenant. It is <tenant>.<group>~<person> for another. See how punches find their tenant. |
- A punch uploaded again with the same data changes nothing.
- A punch uploaded again with other data keeps the first copy. The event contract says consumers should do this. The repeat holds up no punch after it.
- An event that cannot be read as a punch has no time, or no person. The engine keeps it as it came, among the tenant’s unreadable punches. It holds no other punch back.
Recalculation
Section titled “Recalculation”You never ask for a ledger to be worked out. Every write that can change a ledger causes the ledgers of the people it affects to be worked out again. This happens in the background. It starts from the point the change reaches. A write that can change a ledger is, for example, a punch, a correction, a setup or policy change.
| Change | Whose ledgers, from when |
|---|---|
| A fact (a punch, a correction, an entry, a leave request) | The fact’s person, from the earliest instant or workday the fact affects. |
| A person’s setup, or an employment change | That person, from the first day the change names. |
| The tenant’s setup or metadata | Everyone of the tenant. |
| An organization moved or changed | Everyone in it or under it, and everyone assigned to it. |
| A policy layer | Everyone its eligibility rule can pick, from the day it is in force. |
| A policy package adopted, pinned, dropped or published | Everyone of the tenants it applies to. |
| An unlinked person linked | Both people, from the earliest punch that moved. |
Here is how the work is shared.
- Any instance can work out any person. Instances running the engine share the work. No person is tied to one instance, so the instances can sit behind any load balancer. If an instance stops, another takes over its work at once. An instance owns its work only while it is connected to the database.
- Every tenant gets its share. A tenant can have a large change, such as a new policy for everyone. That change does not hold up another tenant’s punches. New punches also go ahead of bulk changes. See fair recalculation. The people of a suspended tenant wait until it resumes.
- A failure stays with its person. Sometimes a person’s ledgers cannot be worked out. A step may fail, or setup may be missing. The person keeps the error and waits. The same facts, policy and software fail the same way, so nothing tries them again on a timer. They are worked out again when anything new affects them, such as a punch or a change of setup or policy. They are also worked out again when an instance running another release takes them. Everyone else is worked out as usual.
- Periods that close on their own close on time. Some policies close periods automatically with
close.after_days. The close is made when it falls due. See period close.
What gets redone
Section titled “What gets redone”A ledger is not started over for every change. Each stage is redone only from the first workday the change reaches.
- A punch on Friday redoes rounding and exceptions from Friday.
- That same punch redoes weekly overtime from the start of the week that holds Friday.
- A change to something every rule can see redoes the whole period. That means the schedule, holidays, employment or the time zone.
- A change to the policy redoes from the first stage and day it reaches. A change to decimal places redoes only the carry.
However little is redone, the result is always the same as working the whole period out from scratch.
Each kept ledger says why it was last worked out and what was redone. It says so in its recalculated note:
{ "why": "marked from 2026-10-16T19:00:00Z", "redone": [ "time: from workday 2026-10-16, ...", "allocate: its windows from 2026-10-12", "exceptions: from workday 2026-10-16, ...", "carry: the whole period" ]}What to watch
Section titled “What to watch”An instance that runs the engine serves the houradvantage_attend_* metrics in /metrics. Their only label is the tenant, and only real tenants appear. A delivery to a name that is not a tenant is counted under none.
The metrics show:
- people waiting to be worked out;
- how long the oldest has waited;
- deliveries by result;
- policy errors;
- unreadable punches.
Alert on houradvantage_attend_oldest_mark_seconds growing. Do not alert on the count. The metrics are listed with the others in the metrics table.
Sometimes the database cannot be reached. The program then says so once, in a warning from houradvantage::outage. When the database is reachable again, it warns a second time. That warning says how long the outage lasted and how many lines were left out.
During the outage, each part that needs the database logs its failure once every 30 seconds for each message. It does not log once for each attempt. This applies only to failures about the database being unavailable. Warnings about anything else are untouched.
From a clock to a timecard helps you find a punch that is delivered but goes nowhere.
Its events
Section titled “Its events”The engine has its own events. They are:
- exceptions raised and resolved;
- timecards approved;
- periods closed and adjusted;
- leave requested, decided and cancelled;
- a person whose recalculation is parked;
- an unlinked person first seen and linked.
The engine keeps them in an event log of its own, apart from Connect’s. It delivers them to the engine’s own sinks, which are each tenant’s and the install’s. See events and sinks. The event reference lists them.
The engine sends an event only when a ledger changes in a way the event reports. Working someone out again with no such change sends nothing.
Events are delivered at least once. Suppose an instance stops partway. Then the person is worked out again, and the same events are sent with the same ids. No event is lost.
Time and Attendance scales up and out: give an instance more cores, or add instances as you grow. There is no fixed limit on employees or clocks. See sizing and scaling.