Skip to main content

dox_queue 3.2.2 copy "dox_queue: ^3.2.2" to clipboard
dox_queue: ^3.2.2 copied to clipboard

Background jobs for the Dox framework: Redis and sync drivers, retries, delays, chains, batches and workers.

3.2.2 #

  • New: the worker warns once in its log when a job may run longer than retryAfter. Then a second worker can take the same job while the first one still runs it. It checks the worker --timeout at start, and the timeout of each job class the first time it runs. timeoutGrace counts too. Nothing else changes. Worker has a new optional retryAfter; bin/queue.dart and the in-process worker pass QueueConfig.retryAfter.
  • New, opt-in: --max-sleep=SECONDS (WorkerOptions.maxSleep). When the queues stay empty, each empty poll doubles the sleep, up to this time. A job sets it back to --sleep. Off by default, so a new job never waits longer than before.
  • Faster: a worker with several queues (--queue=high,default) asks for all of them in one call. The Redis driver runs one script for all queues. It also sends the script by its SHA1 (EVALSHA), not the full text on every pop. When Redis lost the script (a restart or SCRIPT FLUSH), it sends the text once more. The order is the same: the first queue first.
  • New for driver authors: the opt-in interfaces MultiQueuePop (popAny(queues)) and BulkPush (pushAll(payloads), all or none). A driver without them works as before: the worker calls pop() for each queue, and a batch calls push() for each job.
  • Faster: Queue.batch() adds its jobs with BulkPush when the driver has it (the database driver does). A ShouldBeUnique job still goes alone, in its place, so the order is the same.
  • Faster: a queue event with no listener builds no event object and no Future. New QueueEvent.hasListeners(type).
  • Faster: JobPayload.newId() uses one secure random source, not a new one for each id.
  • Fix: an idle worker used a little more memory every few seconds, and it never gave it back. Each sleep of an idle loop (every 3 seconds) left one listener on a shared future that only ends at stop(). That is about 8 MB a day for each loop, and the in-process worker in the web server had it too. Now each sleep has its own completer, and it is removed when the sleep ends. stop() still wakes a sleeping loop at once.
  • Change: every queue log line now starts with the tag [queue] in place of the text Queue: . This is only the log text. The API is the same.

3.2.1 #

  • Fix: a bad REDIS_PORT no longer puts its value in the error. Before, the error showed the value, which can be a secret. Now the error is the fixed text REDIS_PORT must be a number.
  • Fix: the wrong-scheme error of a bad REDIS_URL no longer shows any part of the URL. Before, it showed the text before the first :. For a URL with no scheme, that text can be a user name or a secret token. Now the error is the fixed text REDIS_URL must start with redis:// or rediss://.
  • Fix: a bad REDIS_URL no longer puts the Redis password in the error. Before, a bad port or a wrong scheme gave an error with the full URL, so the password went to the logs. Now the error shows the URL with the user and password hidden.
  • Fix: the queue worker (QueueWorker, bin/queue.dart work) now checks APP_KEY at start, like the web server does. A short or public sample key stops the worker in production and only logs a warning in development, local and test.

3.2.0 #

  • New dox queue:install [--driver=database|redis|sync], run by dox add queue. It writes lib/config/queue.dart, the provider, bin/queue.dart and a sample job, adds the REDIS_* keys for redis, and for database adds dox_queue_database and the create_queue_tables migration. It never overwrites a file. dox_queue now depends on dox_annotation.
  • Breaking: the builder that writes lib/generated/jobs.g.dart moved to dox_builder. So dox_queue no longer depends on analyzer, build, dart_style and glob. Use the dox_builder release that has the job builder, and run build_runner as before. The file and its jobRegistry stay the same. If your build.yaml names the builder dox_queue:jobs, change it to dox_builder:jobs.
  • Breaking: use dox_builder 3.2 or newer with this dox_queue. An older dox_builder has no job builder, so jobs.g.dart is not made. Run dart pub upgrade to move both together. (dox_builder 3.2 with dox_queue 3.1 stops build_runner with "outputs collide"; its CHANGELOG has the build.yaml fix.) A plain Dart app (no Dox) that had only build_runner now also needs dox_builder in dev_dependencies: dart pub add dev:dox_builder.
  • New: QueueConfig(inProcess:) is the new name of workInProcess, the same as ScheduleConfig(inProcess:). workInProcess still works (parameter and getter), but is deprecated. When both are given, inProcess wins.
  • Changed: QueueProvider starts the in-process worker (inProcess: true) in boot(), after setup() of every provider, not in setup(). So the other providers (eg. the mail jobs of dox_mailer) are ready before the first job runs. The worker has its own job store from the provider config. QueueWorker (bin/queue.dart) runs boot() of every provider too. Needs the dox_core release that runs DoxProvider.boot().
  • Breaking: the scheduler process (bin/schedule.dart) no longer starts an in-process queue worker. 3.1 did, because it ran setup() of every provider. The scheduler does not run boot(). Run a worker with inProcess in the web server, or with bin/queue.dart.
  • Breaking: code that runs the providers itself and calls only setup() (a custom runner) no longer starts the in-process worker. Call boot() of every provider after their setup() too.
  • Queue.pruneBatches() with no batch store gives a failed Future, not a throw.
  • Breaking: the database queue driver (DatabaseQueueDriver) moved to the new package dox_queue_database. Add the package and make your queue provider extend its DatabaseQueueProvider in place of QueueProvider. QueueConfig(driver: 'database') without it throws an ArgumentError that names the package.
  • Breaking: QueueTables and the dox queue:table command moved to dox_queue_database. The migration that dox queue:table writes imports package:dox_queue_database/dox_queue_database.dart.
  • Breaking: the batch store moved to dox_queue_database. Queue.batch() needs it, also with the Redis driver. Without it, Queue.batch() throws a StateError that says to add dox_queue_database.
  • Breaking: afterCommit moved to dox_queue_database. Without it, a dispatch with afterCommit on throws a StateError.
  • Breaking: the queued mail classes (SendQueuedMail, SendEncryptedQueuedMail, RedactedMailError and QueueMailQueue) moved to dox_mailer. The saved job names stay dox_queue:SendQueuedMail and dox_queue:SendEncryptedQueuedMail.
  • Breaking: Queue.fake() no longer swaps the mail queue. A custom queue set with Mail.useQueue() is not caught by it. Mail.queue() with the default queue is still caught.
  • Breaking: dox_queue no longer depends on dox_mailer or dox_orm. It depends on dox_core and ioredis only. The unreleased schedule.job() is gone too, with the dox_scheduler dependency: use s.call('send-report', () => SendReport().dispatch()).
  • The repo is now a pub workspace with two packages, dox_queue and dox_queue_database. They share one version and one v<version> tag.
  • New Queue.extend(name, factory): add a queue driver with a QueueDriverFactory.
  • New Queue.useBatches(BatchRepository? repository): set the batch store.
  • New Queue.useTransactions(QueueTransactions? transactions): set the afterCommit support.
  • New JobRegistry.addBuiltIn(JobCodec codec): a package adds its own built-in jobs (dox_mailer uses it).
  • Batch has a public constructor and a public options field, for a BatchRepository.
  • New Queue.decryptData(data, job) decrypts job data. QueueLog and freeUniqueLockOf are exported for driver authors.
  • Fix: with afterCommit, a transaction on a named dox_orm connection no longer counts as open. Only a transaction of the default connection defers the job (it is the one the job waits for). This now lives in dox_queue_database.
  • Fix: the worker did not stop on SIGTERM when Redis was down. A pop waited for a job that never came, so it needed kill -9. Now Worker.run() ends on stop() even when a pop is stuck, so bin/queue.dart stops on SIGTERM. A pop that is already running gets a short grace (5 seconds) to return its job, and that job then runs. The grace applies to every stop: SIGTERM, SIGINT, restart, --max-time, --max-jobs and --memory. A job that a pop returns after the grace is released back to the queue at once, with the attempt the pop counted taken back. The job did not run, so it runs normally later.
  • New opt-in afterCommit for chains and batches: Queue.chain(jobs).dispatch(afterCommit: true) and Queue.batch(jobs).dispatch(afterCommit: true). The same rule as for one job: inside a transaction of the default dox_orm connection, the batch row is saved and the jobs are pushed only after the commit, and a rollback drops it all. Outside a transaction it happens at once. Null takes QueueConfig.afterCommit, and false wins over it. Before the commit, the returned Batch is not saved yet (it has the id and the counts of a new batch). With the sync driver the whole chain runs after the commit, in order (before, each job of it waited on its own), and gives a new id before the commit. Queue.fake() keeps the chain or batch at dispatch(). Needs no schema change.
  • New opt-in batch events: Queue.batchDispatched(), Queue.batchProgress(), Queue.batchFinished(), Queue.batchFailed() and Queue.batchCancelled(). They use the queue events: a QueueListener gets a QueueEvent with the new type values batchDispatched, batchProgress, batchFinished, batchFailed and batchCancelled, and the new field batch (the batch after the step: id, name and the counts). batchFailed also has the error. batchDispatched fires in the process that called dispatch(), before the jobs are pushed. The others fire in the process that counted the step (the worker, or the dispatcher with the sync driver). Each fires once per step, also with many workers. Batch.cancel() now cancels with one atomic step, so batchCancelled fires once. Queue.fake() fires no batch events. Queue.forgetListeners() removes them too.
  • New opt-in chains inside a batch: Queue.batch(jobs).chain(<DoxJob>[A(), B()]). The jobs of the chain run one after the other. The batch counts the chain as one job: done when its last job is done, failed when one of its jobs fails for good (the rest of the chain is dropped, and the batch failure rules count, also allowFailures()). A skipped ShouldBeUnique first job takes the chain out of the counts. A skipped later job, or a next job that can not be read, fails the chain. Works with every driver. Queue.fake() keeps the chains in the new PendingBatch.chains, and the new assertBatchedChain([A, B]) checks them. Batch.add() still takes jobs only. A batch with no chain works as before.
  • Ships an AI agent skill (dox-queue-guide). Install it in your app with dart run skills@ get.
  • New opt-in job batches, like Laravel Bus::batch(): Queue.batch(jobs).name(name).allowFailures().before(job).progress(job).then(job).catchError(job).whenComplete(job).dispatch(queue:, connection:) returns a Batch (id, name, totalJobs, pendingJobs, failedJobs, processedJobs, progress, finished, cancelled, cancel(), add(jobs)). Queue.findBatch(id) reads a batch again. whenComplete is Laravel finally (a reserved word in Dart). The callbacks are jobs, not functions (a function can not be saved). They run once, in the process where the step happened, like dispatchSync(). The new opt-in mixin Batchable gives a job batchId and batch(), so it can skip its work when the batch was cancelled. The first failed job cancels the batch unless allowFailures(). Batches are saved in a new job_batches table of the dox_orm connection of QueueConfig.connection, also with the Redis driver. Make it with the new QueueTables.upBatches(schema) (and downBatches). dox queue:table now adds these lines. An app that ran the older migration adds them in a new migration. An app with no batches needs no table. Each count change is one atomic statement (UPDATE ... RETURNING on SQLite and Postgres, a transaction with a row lock on MySQL and MariaDB), so with many workers each callback runs once. The batch id is saved in a new optional payload field batch. A skipped ShouldBeUnique job is taken out of totalJobs and pendingJobs with no progress call (then and whenComplete run when it was the last open job). A failed job retried with queue:retry is marked in a new optional payload field batchFailed: when it fails again it is not counted again, and when it is done pendingJobs and failedJobs both go down. add() throws a StateError for a finished, cancelled or deleted batch and pushes nothing. An empty batch throws an ArgumentError. A push that throws in dispatch() or add() takes the jobs that were not pushed out of the counts, cancels the batch and throws the error; the jobs pushed before still run and still fire the callbacks. The batch is marked finished before then and whenComplete run, so a late add() throws. The counts are at-least-once: a job that runs twice can be counted twice. failedJobs never goes below 0. Without the table, dispatch() throws a StateError that names QueueTables.upBatches(). The sync driver runs the jobs at dispatch() and counts them (a failed job does not throw). Queue.fake() keeps the batches in the new QueueFake.batches, with assertBatched([test]) and assertBatchCount(n). New command prune-batches --hours=N of bin/queue.dart (and Queue.pruneBatches(before, unfinishedBefore:)) deletes old finished batches, and with --unfinished=N also old batches that never finished.
  • New opt-in job chains, like Laravel Bus::chain(): Queue.chain(jobs).catchError(job).dispatch(queue:, connection:, delay:). The jobs run one after the other. The next job is pushed only when the one before it is done (also after delete() or a middleware that skips it). A release or a retry keeps the chain. When a job fails for good, the rest is dropped and the catch job runs. The rest of the chain is saved in new optional payload fields chain and chainCatch, so it works across worker processes and restarts. Old payloads still read, and a payload without a chain is the same as before. The catch handler is a job, not a function (a function can not be saved). It runs once in the worker where the job failed, like dispatchSync(). With the new opt-in mixin CatchesError it reads the error in caughtError. A ShouldBeUnique job of the chain that is skipped, or a next job that can not be read, stops the chain and runs the catch job. ShouldBeEncrypted jobs stay encrypted inside the chain. The sync driver runs the jobs now, one after the other. Queue.fake() keeps the chains in the new QueueFake.chains, and assertChained([A, B]) checks them. The next job fires the queued event like any dispatch. The worker pushes the next job before it deletes the job that is done, like Laravel. When that push throws, the try counts as failed, so the job is retried (it runs again), and when no try is left it fails and the catch job runs. A crash between the push and the delete can run the next job twice. A failed push counts as a failed try of a job whose handle() worked (exceptionOccurred, and at the last try failed() and the failed event), so give chain jobs more than one try. The unique lock of the job is freed before the push, so a next job with the same unique id is not skipped.
  • New queue events, like Laravel: Queue.queued(), Queue.before() (processing), Queue.after() (processed), Queue.released(), Queue.exceptionOccurred() (the job will be tried again), Queue.failing() (failed for good), Queue.looping() and Queue.stopping(). Each takes a QueueListener, a function that gets a QueueEvent (type, job, job name, id, queue, try number, error, delay). Each event fires once per step. Listeners are per isolate, so add them where the app starts. A listener that throws is logged, and never stops the worker or the dispatch. Queue.forgetListeners() removes them. The sync driver, dispatchSync() and Queue.fake() fire no events. dox_core has no event system, so these are static hooks.
  • New opt-in unique jobs, like Laravel: with ShouldBeUnique (and uniqueId, uniqueFor) and with ShouldBeUniqueUntilProcessing. While a job with the same name and uniqueId is on the queue, dispatch() pushes nothing and returns an empty id (''), so the return type stays Future<String>. The worker frees the lock when the job is done, deleted or failed for good (ShouldBeUniqueUntilProcessing: when the job starts). A release or a retry keeps it. uniqueFor ends the lock after a time (null: no end). The lock is a lock of the default cache store, owned by the job id, so a worker never frees the lock of a newer job. The web app and the workers must use the same cache store (eg. redis). With afterCommit inside a transaction, the lock is taken at the commit. The sync driver frees the lock after the job ran. dispatchSync() does not use the lock. Queue.fake() keeps its own locks, needs no cache, and clear() frees them. The payload of a unique job saves the lock name in a new optional field unique (JobPayload.unique). So the worker frees the lock also when the job class can not be read, and clear frees the locks of the jobs it deletes (it reads the deleted jobs once: Redis in pages of 1000, the database with one LIKE query). Old payloads have no such field and still read. The payload of a job that is not unique does not change. queue:retry does not take the lock. A crash of a worker or of clear leaves the lock: set uniqueFor. A broken payload is logged and skipped by clear. Fix (Redis): a job released by a worker after clear (or after its reservation ran out and another worker took it) no longer comes back on the queue.
  • New job middleware RateLimited(key, max, per), WithoutOverlapping(key, {releaseAfter, expireAfter}) and ThrottlesExceptions(key, {maxAttempts, decay, retryAfter}), like Laravel. RateLimited runs at most max jobs of a key per window, the others go back on the queue until the window ends. WithoutOverlapping runs one job of a key at a time; the others go back after releaseAfter (null: they are dropped). ThrottlesExceptions stops jobs of a key for decay after maxAttempts errors. They keep their counts and locks in the default cache store (Cache()), so every worker that uses the same store (eg. redis) shares them. A release counts as a try: give such jobs more tries or a retryUntil. Unlike Laravel, WithoutOverlapping does not add the class name to its lock. ThrottlesExceptions keeps a fail() or delete() of the job when it then throws. With dispatchSync(), dispatchAfterResponse() and the sync driver there is no queue: when a middleware releases the job, handle() does not run and a warning is logged.
  • New opt-in job middleware, like Laravel: class MyJob extends DoxJob with HasMiddleware and List<JobMiddleware> get middleware. Each JobMiddleware has Future<void> handle(DoxJob job, JobNext next) and wraps handle() of the job. The first one runs first. A middleware can skip the job (it does not call next: the job is done) or put it back with release(job, delay) (it counts as a try, like release() of InteractsWithQueue). The worker, the sync driver and dispatchSync() use them. It is a mixin, so jobs without it work as before, also when they have their own middleware member.
  • New opt-in QueueConfig(failedAtTimestamp: true) and QueueTables.up(schema, failedAtTimestamp: true): failed_jobs.failed_at is a timestamp column in UTC, like Laravel, not a big integer of unix time in milliseconds. The setting counts per queue connection. FailedJob.failedAt is the same DateTime with both types. The database driver reads the column type once, on its first use of failed_jobs, and throws a StateError when the setting and the column do not match, so no wrong value is written. When the type can not be read, it is read again on the next call: with the setting off the call goes on after a warning, with the setting on it throws. On MySQL and MariaDB the time is written with FROM_UNIXTIME() and read with UNIX_TIMESTAMP(), so the session time zone does not change it. The docs have the SQL to change a table with the integer column on SQLite, Postgres and MySQL. With the setting off, the table and the values are as before. The Redis driver does not use it.
  • New opt-in dispatch(afterCommit: true) (also on dispatchIf(), dispatchUnless() and Queue.dispatch()) and QueueConfig(afterCommit: true) for every dispatch, like Laravel afterCommit(). Inside a transaction of the default dox_orm connection, the job is pushed only after the outermost transaction commits. A rollback drops it. Outside a transaction it is pushed at once. afterCommit: false on one dispatch wins over the setting, like Laravel beforeCommit(). dispatch() returns the job id at once. A job that is not in the registry, or data that is not JSON, still throws at dispatch(). The sync driver runs the job after the commit. dispatchSync() and dispatchAfterResponse() do not change. Queue.fake() keeps the job at dispatch(), like Laravel. With nothing new used, dispatch works as before. Needs the next dox_orm (with QueryBuilder.afterCommit()): the dox_orm constraint must go up to that version at release.
  • New opt-in mixin InteractsWithQueue, like Laravel: class MyJob extends DoxJob with InteractsWithQueue. Inside handle() the job can call attempts(), release(delay), fail(error) and delete(). The worker does the call when handle() ends: release() puts the job back on its queue (it counts as a try, so set tries above 1), fail() fails it at once and runs failed(), delete() deletes it with no failed(). The last call wins, and a call wins over an error thrown after it (also a TimeoutException of the job itself, and in dispatchSync() a fail() call gives its error to failed(), while the thrown error still reaches the caller). When the worker timeout fires, the call is dropped and the timeout rules count. Outside a worker (dispatchSync(), dispatchAfterResponse(), the sync driver) attempts() is 1, release() and delete() do nothing, and fail() only runs failed(). Jobs without the mixin work as before, also when they have their own members of these names.
  • New opt-in QueueConfig(serializeSync: true): the sync driver saves the job and reads it back before it runs, like a worker gets it. So a job that is not in the registry, or a field that is not JSON, throws in tests. The default runs the job object as it is.
  • New opt-in queue connections: QueueConfig(connections: {'database': QueueConfig(driver: 'database')}), dispatch(connection: 'database') (also on dispatchIf(), dispatchUnless() and Queue.dispatch()), Queue.driverOf(name) and the --connection=NAME flag for every command of bin/queue.dart. The config itself is the main connection, used when no connection is named. Queue.fake() keeps the name in PushedJob.connection. A config with no connections works as before.
  • New: failed_jobs has a nullable connection column. A failed job of a named connection saves the name there. The main connection leaves it NULL. A failed_jobs table without the column keeps working: the driver checks for the column once and then leaves it out. Add it with table.string('connection').nullable() in a new migration, then restart the workers (they check for the column once).
  • Queue.fake() did not keep the jobs of dispatchSync() and dispatchAfterResponse(), so a test could not check them. Now the fake keeps them in dispatchedSync and dispatchedAfterResponse. The jobs still run, as before. They are not in pushed, so assertPushed() and the other checks work as before. clear() also empties the two new lists.
  • New: dispatchAfterResponse() runs a job after the response is sent, like Laravel. The client does not wait for it. The job runs in the same process, like dispatchSync(). It does not go on the queue, so it returns nothing (no job id) and has no retry. Outside a request it runs soon. An error goes to the exception handler, never to the client. QueueProvider now calls AfterResponse.enable() of dox_core for it. Needs dox_core with AfterResponse.
  • SendQueuedMail and SendEncryptedQueuedMail are now exported. A test with Queue.fake() can check a queued email with queue.assertPushed<SendQueuedMail>().
  • Docs: clear also deletes the reserved (running) jobs of the queue, not only the waiting and delayed ones.
  • Note for custom drivers: a driver that extends QueueDriver gets clear() and pruneFailed() (they throw an UnsupportedError). A driver that implements QueueDriver gets no code from it, so it must add clear() and pruneFailed() itself, or it does not compile.
  • Queue.retryUntilOf() now logs a warning (with the error type) when it can not read the job. Before, it hid every error.
  • JobPayload.retried() takes the new retryUntil as a parameter. The built-in drivers read it with the new Queue.retriedPayload(), so JobPayload does not read the global Queue.config any more. A custom driver that calls retried() should use Queue.retriedPayload(), or the retried job has no retryUntil.

3.1.0 #

  • New opt-in job settings: retryUntil (retry until a time, not tries times), maxExceptions (fail after this many tries that threw) and failOnTimeout (fail at once on a timeout). Jobs without them work as before. retryUntil is read once at dispatch and saved with the job. Rows saved before this change are read as jobs with no retryUntil. queue:retry gives a failed job a fresh start: the tries and the exceptions count go back to 0, and retryUntil is read again from the job class.
  • New: dispatch(delayUntil: DateTime) waits until a time. delay: Duration still works. Give one of them, not both.
  • New: dispatchIf(condition) and dispatchUnless(condition). They return the job id, or null when the job was not dispatched.
  • New worker flags: --backoff=SECONDS[,SECONDS...] (the retry wait of a job with no backoff), --max-jobs=N, --max-time=SECONDS and --memory=MB (stop the worker after the running jobs). All are off by default.
  • New commands of bin/queue.dart: clear [queue] deletes the jobs of a queue. restart makes the running workers stop after their current jobs (it writes a time to the app cache, so the workers must share one cache store). prune-failed --hours=N deletes failed jobs older than N hours (default 24).
  • New QueueDriver.clear() and QueueDriver.pruneFailed(). The Redis and database drivers have them. A custom driver that does not override them throws an UnsupportedError.
  • QueueDriver.release() now also saves job.payload, so the worker can keep the exception count. A custom driver should save it too.
  • Fix: the QueueFake messages said "a UnusedJob". Now only "Uni" and "U" + one consonant (not "n") + vowel give "a", so it says "an UnusedJob" and still "a UniJob".
  • Fix: when Mail.fake() was on before Queue.fake(), Queue.restore() lost a queue set with Mail.useQueue(). Now Queue.fake() does not touch the mail queue while Mail.fake() is on.
  • Fix: the QueueFake check messages had bad grammar, like "a AllTypesJob" and "1 times". Now they say "an AllTypesJob" and "1 time". A name that starts with a "you" sound (like UserJob or EuJob) gets "a".
  • Fix: Queue.restore() did not undo the Mail.useQueue() call of Queue.fake(). With no Queue.configure(), Mail.queue() still found a queue after the test. Now restore() puts back the queue it had before Queue.fake() (also one from Mail.useQueue()). If it had none: no queue, or this queue when Queue.configure() was called.
  • New: Queue.fake() for tests. It keeps every dispatched job in a QueueFake and does not run or save them. Check them with assertPushed<T>([test]), assertPushedTimes<T>(n), assertNotPushed<T>() and assertNothingPushed(). Read them with pushed (each has the job, the queue name and the delay) or jobsOf<T>(). It also catches Mail.queue() and Mail.later(). dispatchSync() still runs the job. Queue.restore() stops the fake.
  • Fix: with Mail.queue(message, encrypt: true), a send error could name the recipient (eg. an SMTP reply 550 <ann@example.com>: mailbox unavailable). The worker wrote that error to its log and to the failed jobs in plain text. Now the encrypted mail job throws a RedactedMailError. Its text has only the error type and the SMTP or HTTP code. The full error text, with the answer of the server, is encrypted with the app key (at most the first 64K characters, counted in UTF-16 code units). Read it with RedactedMailError.decrypt(job.error). When the error can not be encrypted, only the type and the code are kept. Mail jobs without encrypt keep the full error, as before.
  • New: dox queue:table writes a migration for the jobs and failed_jobs tables in db/migration. It calls QueueTables.up and QueueTables.down. It does not overwrite: when a create_queue_tables migration is already there, it prints so and exits with code 1. It is a package command (dox: commands: in pubspec.yaml), so it needs a dox CLI that finds package commands.
  • Needs dox_core with package:dox_core/command.dart.
  • New: a built-in job for Mail.queue() and Mail.later() of dox_mailer. Queue.configure() turns it on. Apps do not add it to lib/generated/jobs.g.dart: every JobRegistry finds the built-in jobs (JobRegistry.builtIn) after its own jobs. With encrypt: true, the mail is saved like a ShouldBeEncrypted job.
  • Now depends on dox_mailer.
  • Deploy the queue worker together with the web app. An old worker does not know the new mail job, so it fails the queued emails.
  • Fix (opt-in): a job that timed out keeps running, and its retry could run at the same time. The new worker flag --timeout-grace=SECONDS (WorkerOptions.timeoutGrace) makes the worker wait for the old run before the next try. The default does not change. For the in-process worker, use QueueConfig(workerTimeoutGrace: ...).
  • New opt-in QueueConfig.redisFromEnv(): reads the Redis server from REDIS_URL, or from REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD and REDIS_TLS. Use it as QueueConfig(redis: QueueConfig.redisFromEnv()). Without it, the default is still localhost:6379.
  • Opt-in ShouldBeEncrypted job mixin: the job data is saved encrypted with the app key (AES-GCM of dox_core). Jobs without it are saved as before.
  • Needs dox_core 3.1.0 or newer.

3.0.0 #

  • The first stable release.

3.0.0-rc.1 #

  • Uses the Logger that dox_core now exports, so it needs dox_core 3.0.0-rc.1.
  • Fix: a Worker started without Dox().initialize() crashed with a LateInitializationError when it logged. Now it logs to stdout, and errors to stderr.

3.0.0-alpha.5 #

  • Works with ioredis 3.0.0, so it works with dox_core 3.0.0-alpha.16 and newer.

3.0.0-alpha.4 #

  • QueueProvider (was a DoxService): extend it in your app, shutdown() is optional.

3.0.0-alpha.3 #

  • A job with no fields no longer gives an "unused variable" warning in lib/generated/jobs.g.dart.

3.0.0-alpha.2 #

  • The builder now writes the job registry to lib/generated/jobs.g.dart. Import it from there.

3.0.0-alpha.1 #

  • First version.
  • Jobs: @Job() and DoxJob with tries, backoff, timeout, queue and a failed() hook.
  • A builder writes lib/jobs.g.dart: it saves and loads the constructor parameters of each job, with no mirrors.
  • dispatch(), dispatchSync() and Queue.dispatch() with delay and queue.
  • Drivers: sync, database (Postgres, MySQL, MariaDB, SQLite) and redis.
  • QueueService sets up the queue in every isolate. workInProcess runs a worker in the web server.
  • QueueWorker for bin/queue.dart: work, failed, retry, forget and flush.
  • Retries with backoff, failed jobs, timeouts, delayed jobs, crashed worker recovery and graceful stop.
  • QueueTables makes the jobs and failed_jobs tables.
0
likes
150
points
1.14k
downloads

Documentation

API reference

Publisher

verified publisherdartondox.dev

Weekly Downloads

Background jobs for the Dox framework: Redis and sync drivers, retries, delays, chains, batches and workers.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dox_annotation, dox_core, ioredis

More

Packages that depend on dox_queue