benmanns / goworker

goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers.
https://www.goworker.org
Other
2.79k stars 241 forks source link

new feature: (optional) Queue priorities #74

Open enriquebris opened 5 years ago

enriquebris commented 5 years ago

This PR adds a new feature: (optional) queue priorities.

Starting now queue's priority could be defined, meaning that jobs from a queue with higher priority will be pulled before jobs from a queue with lower priority.

How to define priorities:

settings := goworker.WorkerSettings{
        URI:            "redis://localhost:6379/",
        Connections:    100,
        Queues:         []string{"med-priority", "low-priority", "high-priority"},
        QueuesPriority: map[string]int{
            "high-priority": 10,
            "med-priority": 100,
                        "low-priority": 200,
        },
        UseNumber:      true,
        ExitOnComplete: false,
        Concurrency:    2,
        Namespace:      "resque:",
        Interval:       5.0,
    }

goworker.SetSettings(settings)

Values

Priorities could be defined from 0 to the max int value. Smaller values mean higher priority. Zero is the highest priority.

Those queues with no defined priority will automatically get the highest priority (zero).

How optional is this?

All the following scenarios are valid:

Compatibility

This new feature does not introduce any compatibility issue with code bases using previous versions.

Other PRs

This PR includes #71