Skip to content

Commit

Permalink
fix: small code cleanups and new flag to toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed May 10, 2022
1 parent 34cfcf8 commit 2a6e5fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ export class Job<DATA = unknown | void> {
return this;
}

/**
* if set, a job is forked via node child process and runs in a seperate/own
* thread
* @param enableForkMode
*/
forkMode(enableForkMode: boolean): this {
this.attrs.fork = enableForkMode;
return this;
}

/**
* Prevents the job from running
*/
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DefaultOptions = {
lockLimit: 0,
defaultLockLifetime: 10 * 60 * 1000,
sort: { nextRunAt: 1, priority: -1 } as const,
forkHelper: 'dist/childWorker.js'
forkHelper: 'dist/childWorker.js'
};

/**
Expand All @@ -34,7 +34,8 @@ export class Agenda extends EventEmitter {
readonly attrs: IAgendaConfig & IDbConfig;

public readonly forkedWorker?: boolean;
public readonly forkHelper?: string;

public readonly forkHelper?: string;

db: JobDbRepository;

Expand Down Expand Up @@ -69,7 +70,7 @@ export class Agenda extends EventEmitter {
return !!this.jobProcessor;
}

async runForkedJob(name: string, jobId: string) {
async runForkedJob(jobId: string) {
const jobData = await this.db.getJobById(jobId);
if (!jobData) {
throw new Error('db entry not found');
Expand Down Expand Up @@ -117,7 +118,7 @@ export class Agenda extends EventEmitter {
};

this.forkedWorker = config.forkedWorker;
this.forkHelper = config.forkHelper;
this.forkHelper = config.forkHelper;

this.ready = new Promise(resolve => {
this.once('ready', resolve);
Expand Down

0 comments on commit 2a6e5fe

Please sign in to comment.