dox_queue 3.1.0
dox_queue: ^3.1.0 copied to clipboard
Background jobs for the Dox framework: Redis, database and sync drivers, retries, delays and workers.
3.1.0 #
-
New opt-in job settings:
retryUntil(retry until a time, nottriestimes),maxExceptions(fail after this many tries that threw) andfailOnTimeout(fail at once on a timeout). Jobs without them work as before.retryUntilis read once at dispatch and saved with the job. Rows saved before this change are read as jobs with noretryUntil.queue:retrygives a failed job a fresh start: the tries and the exceptions count go back to 0, andretryUntilis read again from the job class. -
New:
dispatch(delayUntil: DateTime)waits until a time.delay: Durationstill works. Give one of them, not both. -
New:
dispatchIf(condition)anddispatchUnless(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 nobackoff),--max-jobs=N,--max-time=SECONDSand--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.restartmakes 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=Ndeletes failed jobs older than N hours (default 24). -
New
QueueDriver.clear()andQueueDriver.pruneFailed(). The Redis and database drivers have them. A custom driver that does not override them throws anUnsupportedError. -
QueueDriver.release()now also savesjob.payload, so the worker can keep the exception count. A custom driver should save it too. -
Fix: the
QueueFakemessages 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 beforeQueue.fake(),Queue.restore()lost a queue set withMail.useQueue(). NowQueue.fake()does not touch the mail queue whileMail.fake()is on. -
Fix: the
QueueFakecheck 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 (likeUserJoborEuJob) gets "a". -
Fix:
Queue.restore()did not undo theMail.useQueue()call ofQueue.fake(). With noQueue.configure(),Mail.queue()still found a queue after the test. Nowrestore()puts back the queue it had beforeQueue.fake()(also one fromMail.useQueue()). If it had none: no queue, or this queue whenQueue.configure()was called. -
New:
Queue.fake()for tests. It keeps every dispatched job in aQueueFakeand does not run or save them. Check them withassertPushed<T>([test]),assertPushedTimes<T>(n),assertNotPushed<T>()andassertNothingPushed(). Read them withpushed(each has the job, the queue name and the delay) orjobsOf<T>(). It also catchesMail.queue()andMail.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 reply550 <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 aRedactedMailError. 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 withRedactedMailError.decrypt(job.error). When the error can not be encrypted, only the type and the code are kept. Mail jobs withoutencryptkeep the full error, as before. -
New:
dox queue:tablewrites a migration for thejobsandfailed_jobstables indb/migration. It callsQueueTables.upandQueueTables.down. It does not overwrite: when acreate_queue_tablesmigration is already there, it prints so and exits with code 1. It is a package command (dox: commands:in pubspec.yaml), so it needs adoxCLI that finds package commands. -
Needs dox_core with
package:dox_core/command.dart. -
New: a built-in job for
Mail.queue()andMail.later()of dox_mailer.Queue.configure()turns it on. Apps do not add it tolib/generated/jobs.g.dart: everyJobRegistryfinds the built-in jobs (JobRegistry.builtIn) after its own jobs. Withencrypt: true, the mail is saved like aShouldBeEncryptedjob. -
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, useQueueConfig(workerTimeoutGrace: ...). -
New opt-in
QueueConfig.redisFromEnv(): reads the Redis server fromREDIS_URL, or fromREDIS_HOST,REDIS_PORT,REDIS_USERNAME,REDIS_PASSWORDandREDIS_TLS. Use it asQueueConfig(redis: QueueConfig.redisFromEnv()). Without it, the default is still localhost:6379. -
Opt-in
ShouldBeEncryptedjob 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.0.2 or newer (for
AppConfig.previousKeys).
3.0.0 #
- The first stable release.
3.0.0-rc.1 #
- Uses the
Loggerthatdox_corenow exports, so it needs dox_core 3.0.0-rc.1. - Fix: a
Workerstarted withoutDox().initialize()crashed with aLateInitializationErrorwhen 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()andDoxJobwithtries,backoff,timeout,queueand afailed()hook. - A builder writes
lib/jobs.g.dart: it saves and loads the constructor parameters of each job, with no mirrors. dispatch(),dispatchSync()andQueue.dispatch()withdelayandqueue.- Drivers:
sync,database(Postgres, MySQL, MariaDB, SQLite) andredis. QueueServicesets up the queue in every isolate.workInProcessruns a worker in the web server.QueueWorkerforbin/queue.dart:work,failed,retry,forgetandflush.- Retries with backoff, failed jobs, timeouts, delayed jobs, crashed worker recovery and graceful stop.
QueueTablesmakes thejobsandfailed_jobstables.