APICronStoreDB class
An APICronStore in the database (tables api_cron_job_run and
api_cron_job_lock), shared by all the instances of the API:
- A run is claimed by inserting it: the unique (
job,scheduledAt) index lets only one instance insert it. - A lock is acquired by inserting it (unique
job). An expired lock is deleted (only if still expired) and inserted again: only one instance wins the insert.
Add buildRepositories to the DBRelationalEntityRepositoryProvider of the API, so the tables are generated and checked with the others.
- Inheritance
-
- Object
- APICronStore
- APICronStoreDB
Constructors
-
APICronStoreDB(EntityRepository<
APICronJobRun> runsRepository, EntityRepository<APICronJobLock> locksRepository)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
locksRepository
→ EntityRepository<
APICronJobLock> -
final
-
runsRepository
→ EntityRepository<
APICronJobRun> -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
acquireLock(
String job, String owner, Duration lease, {DateTime? now}) → Future< APICronJobLock?> -
Acquires the lock of
jobforowneruntilnow+lease:nullif another owner holds it (not expired). An expired lock is taken over; a lock ofowneris renewed.override -
claimRun(
APICronJobRun run) → Future< APICronJobRun?> -
Inserts
run, claiming its occurrence:nullif the occurrence already has a run (another instance claimed it).override -
deleteRunsBefore(
String job, DateTime before) → FutureOr< int> -
Deletes the finished runs of
jobscheduled beforebefore(never a APICronRunStatus.running one: it may be resumed). Returns the count.override -
getLock(
String job) → FutureOr< APICronJobLock?> -
The lock of
job, if any.override -
getRun(
String job, DateTime scheduledAt) → FutureOr< APICronJobRun?> -
The run of the occurrence
scheduledAtofjob, if any.override -
lastRun(
String job) → FutureOr< APICronJobRun?> -
The run of
jobwith the latest APICronJobRun.scheduledAt.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
releaseLock(
APICronJobLock lock) → Future< bool> -
Releases
lock(only if still held by its owner).override -
renewLock(
APICronJobLock lock, Duration lease, {DateTime? now}) → Future< bool> -
Renews
lockuntilnow+lease:falseif it's no longer held by its owner (lost: expired and taken over).override -
selectRunningRuns(
String job) → FutureOr< List< APICronJobRun> > -
The runs of
jobwith status APICronRunStatus.running.override -
selectRuns(
String job, {int limit = 20}) → FutureOr< List< APICronJobRun> > -
The latest runs of
job(latest first), at mostlimit.override -
toString(
) → String -
A string representation of this object.
inherited
-
updateRun(
APICronJobRun run, {String? previousOwner}) → Future< bool> -
Note: the check and the update are not atomic (the repositories update
by ID), but the run is updated only by the instance holding the job
lock: the check protects against an instance that lost it.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
buildRepositories(
DBSQLAdapter< Object> adapter) → List<DBSQLEntityRepository< Object> > -
The repositories of the cron tables for
adapter, to be returned by DBRelationalEntityRepositoryProvider.buildRepositories. -
tryResolve(
) → APICronStoreDB? -
An APICronStoreDB with the repositories of the cron entities known by
the entity handlers (registered with buildRepositories), or
null.
Constants
- locksTable → const String
- runsTable → const String