Documentation
¶
Overview ¶
Package claims keeps the claims of a scheduler.Scheduler in a PostgreSQL table, so that an app running several instances runs each minute boundary of a recurring job on one of them. It works on PostgreSQL only.
The table has one row per job id, so it does not grow with time and needs no cleanup. A claim is one statement: an upsert that takes the row only when its stored tick is older than the claimed one and its job is not busy. "Now" and the busy deadline are computed by the database, so instances whose clocks disagree still agree on whether a claim is busy, and a tick more than a minute ahead of the database clock is refused with an error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateTable ¶
CreateTable creates the table of NewBunStore when it does not exist. Every instance can call it at startup: it holds a transaction-level advisory lock while it creates the table, since concurrent CREATE TABLE IF NOT EXISTS statements can fail on PostgreSQL's catalog. The role needs CREATE on the schema even when the table exists.
func NewBunStore ¶
NewBunStore returns a scheduler.Claimer backed by one PostgreSQL table with the columns job_id, tick and busy_until. Call CreateTable with the same table at startup to create it, and pass the store to scheduler.WithClaimer on every instance.
For one job id it grants a tick to exactly one claim, and refuses a tick older than or equal to the last one claimed, so an instance that asks late cannot run a tick again. While a claim is busy, from the claim until it is released or its lease expires, it refuses later ticks too. A tick more than a minute ahead of the database clock is an ez.EINVALID error and is not stored.
Types ¶
This section is empty.