scttnlsn/monq — pull request #28 by scriby (2014-03-20 20:13:01+00:00)
Title: Job prioritization support

Pass a priority when enqueuing a job:

```javascript
queue.enqueue('queue', { data: 'data' }, { priority: 5 }, callback);
```

Jobs of higher priority will be handled before jobs of lower priority. Jobs of the same priority will be handled based on the insertion order. (I made a change to sort by id instead of enqueued time because multiple jobs inserted within the same millisecond were getting returned in a random order. This was causing the test to fail.)

If a priority is not specified, it will default to priority of 0. Negative priorities may be used to de-prioritize jobs below the default level.

Workers can take a minPriority, which causes them to only pick up jobs of that priority or higher:

```javascript
worker = new Worker([ queue ], { minPriority: 1 });
```

This allows certain workers to be reserved for high priority jobs to increase the likelihood of immediate processing. (My current project needs this ability.)

I based these changes on the "retries" branch because the changes to queue.enqueue would have created conflicts otherwise.

Thanks,

Chris