Skip to content

feat(queueing)!: queueing runs from a config, with groups of their own - #11

Closed
arjendevos wants to merge 8 commits into
mainfrom
feat/queue-pools
Closed

arjendevos wants to merge 8 commits into
mainfrom
feat/queue-pools

Conversation

@arjendevos

@arjendevos arjendevos commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Queueing read QUEUE_DRIVER, QUEUE_CONCURRENCY and QUEUE_REDIS_CONNECTION from the environment itself, and every queue shared one pool of workers picked by Priority: a weight, so a busy queue could take every worker and leave none for one that must not wait.

Queueing now runs from config.Queue, handed to queueing.WithConfig, which is required. Workers come in groups, as Laravel Horizon's supervisors:

// config
var Queue = config.Queue{
	Driver:      config.RedisQueueDriver,
	Concurrency: 100, // the default queue: every job outside a group
	Groups: map[string]config.QueueGroup{
		"ci": {Concurrency: 150},
	},
}

// boot
app.WithQueueing(queueing.WithConfig(config.Queue), queueing.WithQueues(routes.Queues))

// routes
func Queues(engine *queueing.Engine) {
	engine.Group("ci", func(group *queueing.Group) {
		group.Job(new(LaunchRunnerJob))
	})
	engine.Job(new(SendWelcomeJob)) // default queue
}
  • A job registered in a group goes on the group's queue, whatever its Queue() says; Dispatch takes the queue from the engine.
  • Each group is an asynq server of its own in the same worker process, with the workers its config gives it. Jobs outside a group run on the default queue's Concurrency, by Priority across the queues they name, as before.
  • The worker refuses to start for a group the config gives no workers, or a job outside a group naming a group's queue, rather than sharing silently. A configured group with no jobs is a warning.
  • SIGTERM or an interrupt shuts every server down and lets jobs in flight finish; SIGTSTP stops them taking new ones, as asynq's Run does.
  • A job that names no queue goes to the default queue, which the default workers now always read. Before, naming a queue on any job left those never run.

Breaking: queueing.WithConfig is required (an error without it), NewEngine takes the config, and EngineResolver's Consume and Dispatch take the groups and the queue. The queue driver type stays private: read it with env.Enum("QUEUE_DRIVER", config.SynchronousQueueDriver). To upgrade, pass a config.Queue with the driver and concurrency the environment used to give.

Tested: tests/queueing covers the required config, unknown drivers, a group's queue, and how jobs and groups become the worker's asynq servers (one per group, one for the rest), including the refusals. A run against a real Redis gave the default queue 2 workers with 6 blocking jobs queued; a job in a ci group of 1 worker still ran at once.

Every queue shared one pool of QUEUE_CONCURRENCY workers, picked by
Priority: a weight, so a busy queue could take every worker and leave
none for one that must not wait.

A job can now say Concurrency() beside Queue(). Each queue with one gets
an asynq server of its own in the same worker, with that many workers,
as a Laravel Horizon supervisor; queues without one share
QUEUE_CONCURRENCY by Priority as before. SIGTERM or an interrupt shuts
every server down, letting jobs in flight finish.

A job that names no queue goes to asynq's default queue, which the
worker now always listens to: before, naming a queue on any job left
those never run.
How many workers a queue gets is the queue's, not each job's: jobs on one
queue could ask for different numbers. A channel is now declared once on
the engine, engine.Channel("ci", 150), and a job is on it by naming it in
Queue(), as a Laravel Horizon supervisor in config.
A queue is only where a job waits, as in Laravel. Which workers take from
it, and how many, is a supervisor's: engine.Supervisor("ci", 150, "ci")
adds a group of 150 workers reading the ci queue, and one reading several
queues takes from them in the order given. Queues no supervisor reads
share QUEUE_CONCURRENCY by Priority, as before.
@arjendevos arjendevos changed the title feat(queueing): a queue can have workers of its own feat(queueing): supervisors give queues workers of their own Nov 23, 2026
Queueing read QUEUE_DRIVER, QUEUE_CONCURRENCY and QUEUE_REDIS_CONNECTION
from the environment itself. It now runs from config.Queue, handed to
queueing.WithConfig, which it needs: without one, dispatching or working
fails with ErrNoConfig.

Workers come in groups. engine.Group("ci", ...) registers jobs on the ci
queue, whatever their Queue() says, and the config's Groups["ci"] gives
them workers of their own; every job outside a group runs on the
default queue's Concurrency, as before. A group the config gives no
workers stops the worker from starting, rather than sharing silently.
The supervisors this pull request had before are gone.

BREAKING CHANGE: queueing.WithConfig is required, NewEngine takes the
config, EngineResolver's Consume and Dispatch take the groups and the
queue, and config's queue driver type is exported as QueueDriver.
@arjendevos arjendevos changed the title feat(queueing): supervisors give queues workers of their own feat(queueing)!: queueing runs from a config, with groups of their own Nov 23, 2026
Comment thread config/queue.go Outdated
type queueDriver string
// QueueDriver is how jobs run: sync where they are dispatched, redis on
// the worker.
type QueueDriver string

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this uppercase, the entire fucking idea of the config/ thing is that most things stay private

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private again in 25f68a2, and the same for the cache driver (#14) and the new Redis mode type (#15). An app reads them with env.Enum("QUEUE_DRIVER", config.SynchronousQueueDriver).

Comment thread config/queue.go
// Groups is each queue group's workers of its own, by the name
// engine.Group registers its jobs under. A group registered without one
// stops the worker from starting.
Groups map[string]QueueGroup

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not call it channel and also call it engine.channel? or is that confusing with the queue() on the job itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping Group: "channel" reads as a Go chan, and a group is more than a queue name, it's its jobs plus workers of their own. It also stays apart from a job's Queue(), which the group overrides.

A pool was a third name beside queue and group for what is one asynq
server: a group's workers, or the default ones. Server says what it is, and
the default one is the server with no group, so the second "default"
constant goes.

Copy link
Copy Markdown
Contributor Author

Folded into #17.

@arjendevos arjendevos closed this Nov 23, 2026
@arjendevos
arjendevos deleted the feat/queue-pools branch November 23, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant