@botmesh/core - v2.0.0-alpha.2
    Preparing search index...

    Class MemoryScheduleStore

    Reference, in-process ScheduleStore. Nothing survives the process.

    Implements

    Index
    • Insert the task if absent. If it exists with the same kind and spec, keep it untouched (that is how a restart keeps its nextRunAt); if either differs, overwrite kind, spec and nextRunAt with the given ones (the fencing token is kept). Returns the stored record.

      Parameters

      • rec: Pick<ScheduleRecord, "id" | "kind" | "spec" | "nextRunAt">
      • now: number

      Returns Promise<ScheduleRecord>

    • Atomic claim: succeeds only when nextRunAt !== null && nextRunAt <= now and the record has no live lease (leaseUntil absent or <= now). Then it sets leaseOwner = owner, leaseUntil = now + leaseMs and increments fencingToken. Returns null otherwise (not due, leased elsewhere, or unknown id).

      Parameters

      • id: string
      • owner: string
      • now: number
      • leaseMs: number

      Returns Promise<ClaimResult | null>

    • Set leaseUntil only if fencingToken still matches; false means the lease was lost.

      Parameters

      • id: string
      • fencingToken: number
      • leaseUntil: number

      Returns Promise<boolean>

    • Commit an occurrence only if fencingToken still matches: write the patch, clear the lease and set updatedAt = now. false when stale (claimed again since) or deleted.

      Parameters

      • id: string
      • fencingToken: number
      • patch: CompletePatch
      • now: number

      Returns Promise<boolean>

    • Remove the record. The id's fencing token is kept as a high-water mark: a later register() of the same id starts from it, so tokens never go backwards per id.

      Parameters

      • id: string

      Returns Promise<void>