InMemoryScheduleStore

org.llm4s.agent.service.InMemoryScheduleStore
@Experimental
final class InMemoryScheduleStore extends ScheduleStore

The ScheduleStore of an InMemoryCheckpointer (InMemoryCheckpointer.scheduleStore, #2446): schedules and firings in memory, under a lock of its own, every time judged and stamped by the checkpointer's clock. Each call is one step under the lock, so a claim, a create's count and a settle are atomic. The store-wide calls read every schedule or firing it holds: it is the reference store, for tests and one process.

Attributes

Source
InMemoryScheduleStore.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def claim(schedule: Schedule, fireAt: Instant, nextFireAt: Instant, threadId: ThreadId, missed: Int): Result[Option[ClaimedFiring]]

Claims schedule's fire time fireAt for one firing on threadId that passed over missed later fire times, and moves the schedule's next fire time to nextFireAt, in one step: only while the stored schedule exists, is not paused, its next fire time is still fireAt, its target still schedule.target (the one threadId was chosen under), and its cron expression and zone still schedule.cron and schedule.zone (the cadence nextFireAt was computed from), and no firing of fireAt exists. Answers the firing, claimed now by the store's clock, with the schedule as the claim left it (its current input, which the firing runs with), or None when another claim came first, or the schedule was paused, deleted, given another next fire time, another target or another cron expression or zone since it was read: read it again and claim from that. An edit of only the input or the other fields does not stop the claim. A claim leaves the schedule's revision and updatedAt as they were. A ValidationError when fireAt is not schedule.nextFireAt: only the next fire time the caller read can be claimed.

Claims schedule's fire time fireAt for one firing on threadId that passed over missed later fire times, and moves the schedule's next fire time to nextFireAt, in one step: only while the stored schedule exists, is not paused, its next fire time is still fireAt, its target still schedule.target (the one threadId was chosen under), and its cron expression and zone still schedule.cron and schedule.zone (the cadence nextFireAt was computed from), and no firing of fireAt exists. Answers the firing, claimed now by the store's clock, with the schedule as the claim left it (its current input, which the firing runs with), or None when another claim came first, or the schedule was paused, deleted, given another next fire time, another target or another cron expression or zone since it was read: read it again and claim from that. An edit of only the input or the other fields does not stop the claim. A claim leaves the schedule's revision and updatedAt as they were. A ValidationError when fireAt is not schedule.nextFireAt: only the next fire time the caller read can be claimed.

Attributes

Source
InMemoryScheduleStore.scala
def create(schedule: Schedule, nextFireAt: Instant, maxPerTenant: Int): Result[Schedule]

Stores schedule as a new schedule of its tenant, at revision 1 - or, when the tenant had a schedule of the id that was deleted, one above the last revision that one reached - created and updated now by the store's clock, its next fire time nextFireAt, and answers it as stored. Refused with ScheduleError.Exists when the tenant has a schedule of the id, and otherwise with ScheduleError.TooMany when it already has maxPerTenant.

Stores schedule as a new schedule of its tenant, at revision 1 - or, when the tenant had a schedule of the id that was deleted, one above the last revision that one reached - created and updated now by the store's clock, its next fire time nextFireAt, and answers it as stored. Refused with ScheduleError.Exists when the tenant has a schedule of the id, and otherwise with ScheduleError.TooMany when it already has maxPerTenant.

Attributes

Source
InMemoryScheduleStore.scala
def delete(tenantId: Option[TenantId], id: ScheduleId): Result[Unit]

Removes the tenant's schedule id; ScheduleError.NotFound when there is none. Its firings stay until reclaimed.

Removes the tenant's schedule id; ScheduleError.NotFound when there is none. Its firings stay until reclaimed.

Attributes

Source
InMemoryScheduleStore.scala
def due(redriveAfter: FiniteDuration, limit: Int): Result[DueSchedules]

The store's now, up to limit schedules due by it, and up to limit firings claimed more than redriveAfter before it and not yet settled; see DueSchedules.

The store's now, up to limit schedules due by it, and up to limit firings claimed more than redriveAfter before it and not yet settled; see DueSchedules.

Attributes

Source
InMemoryScheduleStore.scala
def firings(tenantId: Option[TenantId], id: ScheduleId, limit: Int): Result[Vector[Firing]]

Up to limit firings of the tenant's schedule id, newest fire time first, whether or not the schedule still exists; empty when there are none.

Up to limit firings of the tenant's schedule id, newest fire time first, whether or not the schedule still exists; empty when there are none.

Attributes

Source
InMemoryScheduleStore.scala

The store's time: what every time this store records and every age it judges is measured by.

The store's time: what every time this store records and every age it judges is measured by.

Attributes

Source
InMemoryScheduleStore.scala
def reclaim(lifetime: FiniteDuration, limit: Int): Result[Int]

Removes up to limit settled firings that have no thread left to delete and were settled lifetime or more ago, by the store's clock, oldest first, and answers how many it removed. Never an unsettled firing.

Removes up to limit settled firings that have no thread left to delete and were settled lifetime or more ago, by the store's clock, oldest first, and answers how many it removed. Never an unsettled firing.

Attributes

Source
InMemoryScheduleStore.scala

The tenant's schedule id; ScheduleError.NotFound when there is none.

The tenant's schedule id; ScheduleError.NotFound when there is none.

Attributes

Source
InMemoryScheduleStore.scala
def schedules(tenantId: Option[TenantId], thread: Option[ThreadId], after: Option[ScheduleId], limit: Int): Result[Vector[Schedule]]

Up to limit of the tenant's schedules, by id in the byte order of its ASCII characters (COLLATE "C" in SQL, never a locale's collation; ScheduleId's Ordering), after after when it is set; only those bound to thread (ScheduleTarget.Thread) when it is set.

Up to limit of the tenant's schedules, by id in the byte order of its ASCII characters (COLLATE "C" in SQL, never a locale's collation; ScheduleId's Ordering), after after when it is set; only those bound to thread (ScheduleTarget.Thread) when it is set.

Attributes

Source
InMemoryScheduleStore.scala
def settle(firing: Firing, outcome: FiringOutcome): Result[Firing]

Settles firing with outcome, now by the store's clock, and answers it as stored: a firing settled already keeps its first outcome and is answered with it. ScheduleError.NotFound for a firing the store no longer holds.

Settles firing with outcome, now by the store's clock, and answers it as stored: a firing settled already keeps its first outcome and is answered with it. ScheduleError.NotFound for a firing the store no longer holds.

Attributes

Source
InMemoryScheduleStore.scala
def threadDeleted(firing: Firing): Result[Unit]

Records that firing's thread has been deleted, so it is no longer listed by threadsToDelete.

Records that firing's thread has been deleted, so it is no longer listed by threadsToDelete.

Attributes

Source
InMemoryScheduleStore.scala

Up to limit settled firings whose thread is due for deletion by the store's clock (Firing.deleteThreadAt), earliest deadline first.

Up to limit settled firings whose thread is due for deletion by the store's clock (Firing.deleteThreadAt), earliest deadline first.

Attributes

Source
InMemoryScheduleStore.scala
def update(schedule: Schedule, nextFireAt: Option[Instant]): Result[Schedule]

Replaces the tenant's schedule of schedule.id with schedule, if the stored one is still at schedule.revision: answers it at the next revision, updated now by the store's clock, its creation time kept. Its next fire time is nextFireAt when set - an edit of the cron expression or the zone passes the recomputed one - and otherwise the stored one, whatever schedule.nextFireAt says, so an edit of the input or the other fields never conflicts with a claim and never puts the schedule back on a fire time already claimed. ScheduleError.Conflict, naming the stored revision, when the schedule has been updated since it was read (a claim does not count), or when nextFireAt is set at or before the fire time of one of the schedule's firings, already claimed: recompute it from a fresh read; ScheduleError.NotFound when the tenant has no schedule of the id. The store keeps its own copy of the input: changing the caller's afterwards changes nothing stored.

Replaces the tenant's schedule of schedule.id with schedule, if the stored one is still at schedule.revision: answers it at the next revision, updated now by the store's clock, its creation time kept. Its next fire time is nextFireAt when set - an edit of the cron expression or the zone passes the recomputed one - and otherwise the stored one, whatever schedule.nextFireAt says, so an edit of the input or the other fields never conflicts with a claim and never puts the schedule back on a fire time already claimed. ScheduleError.Conflict, naming the stored revision, when the schedule has been updated since it was read (a claim does not count), or when nextFireAt is set at or before the fire time of one of the schedule's firings, already claimed: recompute it from a fresh read; ScheduleError.NotFound when the tenant has no schedule of the id. The store keeps its own copy of the input: changing the caller's afterwards changes nothing stored.

Attributes

Source
InMemoryScheduleStore.scala