Skip to content

Conversation

@arttor
Copy link

@arttor arttor commented Aug 1, 2025

Closes #856

Allows workers to process dynamic queue names. Dynamic queue priorities can be set using wildcard (*) patterns:

	srv := NewServer(redisConnOpt, Config{
		Queues: map[string]int{
			"critical":          10, // exact match
			"email:*":           5,  // wildcard suffix match
			"email:important:*": 6,  // wildcard longest prefix wins
			"*:transfer:*":      7,  // multiple wildcards
			"*":                 3,  // default
		},
		StrictPriority: true,
		DynamicQueues:  true,
	})
  1. tasks from queue named critical will be processed first (priority 10)
  2. then tasks from queues containing :transfer: in its name (priority 7)
  3. then from queues starting from email:important (priority 6)
  4. then starting from email: (priority 5)
  5. then other queues (priority 3)

Implementation details

  • No changes on client needed.
  • No changes in Redis data structure or migration needed.
  • For now, only strict priority for dynamic queue implemented.
  • PR adds queueManager that periodically polls (by default every 5s) all existing queues from existing Redis SET AllQueues. The manager assigns priorities to new queues based on the wildcard configuration.

Motivation

The feature addresses the use case described in #856, enabling dynamic queue creation at runtime (e.g., queue names based on domain objects - for us it is S3 bucket names for data migration). This is particularly useful for applications requiring flexible queue management without predefined queue names.

Side notes

Apologies for submitting a large PR without a prior design proposal. The API change is minimal, and the implementation is best understood by reviewing the source code. Feedback is welcome!

Future work

This PR lays the groundwork for addressing #850, which proposes dynamic queue priority configuration. Potential next steps include:

  1. Replace Redis SET AllQueues with a Redis SortedSet, using scores to represent queue priorities.
  2. On the first enqueue add new queue to the sorted set with priority -1
  3. Update queueManager to periodically fetch new queues with score -1 and assign priorities based on the dynamic configuration.
  4. Add method to the inspector to change queue priority directly in redis which will automatically affect all workers
  5. Since queue priority now stored in Redis, Dequeue logic can be optimised. Looping over queue list could be moved to dequeue Lua script. It will reduce number of requests to Redis from O(N) to O(1) for each message dequeue operation, where N is number of queues in the config.

Signed-off-by: Artem Torubarov <[email protected]>
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.

[FEATURE REQUEST] Support dynamic queue

1 participant