FileQueueLease class final

A QueueLease kept in a small file.

Every isolate and process that opens the same queue storage must use a lease at the same path, for example a file next to the database in the application support directory. The Android background job runs in a separate isolate of the same process, where RandomAccessFile.lock does not exclude anyone, so this lease relies on exclusive file creation instead:

  • The holder is whoever created the file. Its content names the holder and when the lease expires.
  • renew rewrites the expiry. A holder that let the lease expire has lost it, even if nobody took it over yet.
  • An expired lease is taken over under a short-lived guard file (<path>.takeover), so two runners cannot both take it.

Each FileQueueLease object is one holder. Create one per runner and do not share it between isolates.

This is a cooperative lock between parts of one app, not a security boundary, and it depends on the device clock. Its guarantee is limited by ttl: if a holder is frozen for longer than ttl while it runs a task, another runner can take over and run that task again. Pick a ttl that is longer than any pause you expect, and keep handlers idempotent, as every durable_queue handler should be.

Implemented types

Constructors

FileQueueLease(String path, {Duration ttl = const Duration(minutes: 2), DateTime now()?})
Creates a lease kept at path.

Properties

hashCode → int
The hash code for this object.
no setterinherited
path → String
Where the lease is kept.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
ttl → Duration
How long the lease stays valid without renew.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
release() → Future<void>
Gives up the lease if this object holds it.
override
renew() → Future<bool>
Extends the lease by ttl. Returns false if this object no longer holds it, for example because it was not renewed in time and another runner took it over.
override
toString() → String
A string representation of this object.
inherited
tryAcquire() → Future<bool>
Takes the lease if it is free or abandoned, and returns whether this object holds it now. Returns true if it already held it.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited