Skip to content

Route tasks to queues

You’ll split work into emails, reports and default queues, route tasks there without touching call sites, and run a worker group per queue.

  • An app shared by producers and workers.
import 'package:gisila_queue/gisila_queue.dart';
final router = Router()
..route('emails.*', queue: 'emails')
..routeMatching(RegExp(r'^reports\.(daily|monthly)$'), queue: 'reports');
final app = GisilaQueue.redis(namespace: 'shop', router: router);

Rules are checked in order; the first match wins. Globs are anchored and only * is special.

app.task<void>('thumbnails.render', renderThumbnail, queue: 'cpu');

The task default applies only where the task is registered in the producing process, and only when the router doesn’t match.

await sendEmail.applyAsync(args: [userId], queue: 'emails-priority');

An explicit queue: beats everything. Order: call, router, task default, GisilaQueue.defaultQueue ('default').

Terminal window
dart run bin/worker.dart --namespace=shop --queues=emails --concurrency=32
dart run bin/worker.dart --namespace=shop --queues=reports --concurrency=2
dart run bin/worker.dart --namespace=shop --queues=default,emails,reports --concurrency=8

The last worker drains default first and helps with the others when default is empty.

With a control channel (on by default in GisilaQueue.redis and WorkerCli):

await app.controlChannel.publish(const ControlMessage.pause('emails'));
// ... fix the mail provider ...
await app.controlChannel.publish(const ControlMessage.resume('emails'));

Messages keep accumulating on the paused queue and run after resume.

print(router.resolve('emails.welcome')); // emails
print(router.resolve('reports.daily')); // reports
print(router.resolve('reports.weekly')); // null → task default or 'default'
Terminal window
dart run gisila_queue:gisila_queue inspect --namespace=shop --queues=default,emails,reports