Skip to content

Commit 2a6e5fe

Browse files
committed
fix: small code cleanups and new flag to toggle
1 parent 34cfcf8 commit 2a6e5fe

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Job.ts

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ export class Job<DATA = unknown | void> {
124124
return this;
125125
}
126126

127+
/**
128+
* if set, a job is forked via node child process and runs in a seperate/own
129+
* thread
130+
* @param enableForkMode
131+
*/
132+
forkMode(enableForkMode: boolean): this {
133+
this.attrs.fork = enableForkMode;
134+
return this;
135+
}
136+
127137
/**
128138
* Prevents the job from running
129139
*/

src/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const DefaultOptions = {
2424
lockLimit: 0,
2525
defaultLockLifetime: 10 * 60 * 1000,
2626
sort: { nextRunAt: 1, priority: -1 } as const,
27-
forkHelper: 'dist/childWorker.js'
27+
forkHelper: 'dist/childWorker.js'
2828
};
2929

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

3636
public readonly forkedWorker?: boolean;
37-
public readonly forkHelper?: string;
37+
38+
public readonly forkHelper?: string;
3839

3940
db: JobDbRepository;
4041

@@ -69,7 +70,7 @@ export class Agenda extends EventEmitter {
6970
return !!this.jobProcessor;
7071
}
7172

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

119120
this.forkedWorker = config.forkedWorker;
120-
this.forkHelper = config.forkHelper;
121+
this.forkHelper = config.forkHelper;
121122

122123
this.ready = new Promise(resolve => {
123124
this.once('ready', resolve);

0 commit comments

Comments
 (0)