EmbeddedWorkers class final

Queue worker and scheduler isolates started by Application.serveWith (serve --embed-queue --embed-scheduler), so one process can serve HTTP, process jobs and run the schedule without supervisord or cron.

Each role runs its own application in its own isolate, so a slow job never blocks the HTTP event loop. An isolate that ends on its own (a queue worker restarting after queue:restart or a timed-out job) is started again at once. One that crashes is started again after crashDelay: a second per crash in the last minute, and a minute between attempts, each logged as an error, once there were more than maxCrashesPerMinute; it is never given up while the server runs. Uncaught asynchronous errors inside an isolate are logged, not fatal. stop asks each isolate to finish its current job or tick and waits up to the shutdown timeout before killing it.

Application.serveWith manages it; custom entrypoints can use it too.

Constructors

EmbeddedWorkers(ApplicationFactory factory, {required List<EmbeddedRole> roles, required Logger logger, ScheduleCommandRunner? commandRunner, SendPort? coordinator, Duration crashDelay(int crashes) = defaultCrashDelay})
Runs the roles (queue worker, scheduler) of applications from factory beside the HTTP server.

Properties

commandRunner ↔ ScheduleCommandRunner?
Runs the scheduled commands.
getter/setter pair
coordinator → SendPort?
The server's coordinator (Coordinator.listen()), so the embedded isolates share its process cache store, rate limits and locks with the HTTP workers: a token a job revokes is refused by the server, a limit a scheduled task raises holds for the next request. Without it each isolate has a coordinator of its own.
final
crashDelay → Duration Function(int crashes)
The wait before starting a role again after its isolate crashed, given how many times it crashed in the last minute (defaultCrashDelay).
final
factory → ApplicationFactory
Builds each role's application.
final
hashCode → int
The hash code for this object.
no setterinherited
logger → Logger
Logs starts, crashes and stops.
final
roles → List<EmbeddedRole>
The roles run.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
start() → Future<void>
Starts every role in its own isolate.
stop({Duration timeout = const Duration(seconds: 30)}) → Future<void>
Asks every isolate to stop after its current job or tick (the scheduler waits up to three quarters of timeout for its running tasks); kills the ones still running after timeout.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Methods

defaultCrashDelay(int crashes) → Duration
A second per crash in the last minute; a minute past maxCrashesPerMinute.

Constants

maxCrashesPerMinute → const int
Crashes in a minute beyond which a role is started only once a minute.