Skip to content

Commit

Permalink
feat: allow priority when queuing jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sealos committed Jun 26, 2024
1 parent 4394830 commit c14e468
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/agenda/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ const debug = createDebugger("agenda:now");
* @function
* @param name name of job to schedule
* @param data data to pass to job
* @param options
*/
export async function now<T extends JobAttributesData>(
this: Agenda,
name: string,
data: T
data: T,
options?: {
priority: string | number
}
): Promise<Job> {
debug('Agenda.now(%s, [Object])', name);
try {
const job = this.create(name, data);

job.schedule(new Date());

if (options?.priority) {
job.priority(options.priority);
}

await job.save();

return job;
Expand Down
3 changes: 1 addition & 2 deletions lib/job/priority.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Job } from ".";
import { parsePriority } from "../utils";


/**
* Sets priority of the job
* @param priority priority of when job should be queued
*/
export function priority(this: Job, priority: string): Job {
export function priority(this: Job, priority: string | number): Job {
this.attrs.priority = parsePriority(priority);
return this;
}

0 comments on commit c14e468

Please sign in to comment.