Skip to content

Commit

Permalink
Added a priority option to jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rizen committed Apr 24, 2024
1 parent f6042b2 commit 36196cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ outline: deep
* NOTE: Because of the above you may want to check out the new acceptedFileExtensions attribute in ving schemas and migrate your S3File integrations to use it.
* Implemented: add a display of an s3file thumbnail to the page generator #105
* Fixed: pulumi doesn't create the nodmods.zip file as it should #110
* Added a priority option to jobs.

## 2024-04-23
* Created SelectInput component to replace FormSelect. However, you should use FormInput with type select instead of using this directly in most cases.
Expand Down
12 changes: 9 additions & 3 deletions ving/jobs/queue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { useRedis } from '#ving/redis.mjs';
* @param {Object} options An object with optional properties.
* @param {string} options.queueName The name of the queue to add this job to. Defaults to `jobs`.
* @param {number} options.delay The number of milliseconds to wait before executing this job. Defaults to running as soon as possible.
* @param {number} options.priority A number ranging from `1` to `2097152` where `1` is the highest possible priority. Defaults to `2097152`.
*/
export const addJob = async (type, data = {}, options = { queueName: 'jobs ' }) => {
const queue = new Queue(options?.queueName || 'jobs');
const job = await queue.add(type, data, {
const jobOptions = {
connection: useRedis(),
removeOnComplete: {
age: 3600, // keep up to 1 hour
Expand All @@ -22,8 +23,13 @@ export const addJob = async (type, data = {}, options = { queueName: 'jobs ' })
removeOnFail: {
age: 24 * 3600, // keep up to 24 hours
},
delay: options?.delay,
});
priority: 2097152
}
if (options?.delay)
jobOptions.delay = options?.delay;
if (options?.priority)
jobOptions.priority = options?.priority;
const job = await queue.add(type, data, jobOptions);
ving.log('jobs').info(`Job ${job.id} ${job.name} enqueued.`);
await queue.close();
}

0 comments on commit 36196cb

Please sign in to comment.