@lokalise/background-jobs-common
Advanced tools
Comparing version 9.1.0 to 10.0.0
@@ -87,3 +87,5 @@ "use strict"; | ||
this._worker = this.factory.buildWorker(this.config.queueId, ((job) => this.processInternal(job)), { | ||
...(0, ts_deepmerge_1.merge)(constants_1.DEFAULT_WORKER_OPTIONS, this.config.workerOptions), | ||
...(0, ts_deepmerge_1.merge)(constants_1.DEFAULT_WORKER_OPTIONS, this.config.workerOptions, { | ||
autorun: this.config.workerAutoRunEnabled !== false, | ||
}), | ||
connection: (0, utils_1.sanitizeRedisConfig)(this.config.redisConfig), | ||
@@ -90,0 +92,0 @@ prefix: this.config.redisConfig?.keyPrefix ?? undefined, |
@@ -7,4 +7,4 @@ import type { BaseJobPayload } from '../types'; | ||
export declare class FakeBackgroundJobProcessor<JobData extends BaseJobPayload> extends AbstractBackgroundJobProcessor<JobData> { | ||
constructor(dependencies: Omit<BackgroundJobProcessorDependencies<JobData>, 'bullmqFactory' | 'transactionObservabilityManager'>, queueName: string, redisConfig: RedisConfig, isTest?: boolean); | ||
constructor(dependencies: Omit<BackgroundJobProcessorDependencies<JobData>, 'bullmqFactory' | 'transactionObservabilityManager'>, queueName: string, redisConfig: RedisConfig, isTest?: boolean, workerAutoRunEnabled?: boolean); | ||
protected process(_job: Job<JobData>): Promise<void>; | ||
} |
@@ -7,3 +7,3 @@ "use strict"; | ||
class FakeBackgroundJobProcessor extends AbstractBackgroundJobProcessor_1.AbstractBackgroundJobProcessor { | ||
constructor(dependencies, queueName, redisConfig, isTest = true) { | ||
constructor(dependencies, queueName, redisConfig, isTest = true, workerAutoRunEnabled = true) { | ||
super({ | ||
@@ -27,2 +27,3 @@ transactionObservabilityManager: { | ||
redisConfig, | ||
workerAutoRunEnabled, | ||
}); | ||
@@ -29,0 +30,0 @@ } |
@@ -11,6 +11,7 @@ import type { CommonLogger, ErrorReporter, RedisConfig, TransactionObservabilityManager } from '@lokalise/node-core'; | ||
queueOptions?: Omit<Partial<QueueOptionsType>, 'connection' | 'prefix'>; | ||
workerOptions: Omit<Partial<WorkerOptionsType>, 'connection' | 'prefix'>; | ||
workerOptions: Omit<Partial<WorkerOptionsType>, 'connection' | 'prefix' | 'autorun'>; | ||
redisConfig: RedisConfig; | ||
barrier?: BarrierCallback<JobPayload, ExecutionContext, JobReturn, JobType>; | ||
lazyInitEnabled?: boolean; | ||
workerAutoRunEnabled?: boolean; | ||
}; | ||
@@ -17,0 +18,0 @@ export type BackgroundJobProcessorDependencies<JobPayload extends object, JobReturn = void, JobType extends SafeJob<JobPayload, JobReturn> = Job<JobPayload, JobReturn>, QueueType extends Queue<JobPayload, JobReturn, string, JobPayload, JobReturn, string> = Queue<JobPayload, JobReturn, string, JobPayload, JobReturn>, QueueOptionsType extends QueueOptions = QueueOptions, WorkerType extends Worker<JobPayload, JobReturn> = Worker<JobPayload, JobReturn>, WorkerOptionsType extends WorkerOptions = WorkerOptions, ProcessorType extends BullmqProcessor<JobType, JobPayload, JobReturn> = BullmqProcessor<JobType, JobPayload, JobReturn>> = { |
{ | ||
"name": "@lokalise/background-jobs-common", | ||
"version": "9.1.0", | ||
"version": "10.0.0", | ||
"files": ["dist", "LICENSE.md", "README.md"], | ||
@@ -55,5 +55,5 @@ "author": { | ||
"toad-scheduler": "^3.0.1", | ||
"typescript": "5.7.2", | ||
"typescript": "5.7.3", | ||
"vitest": "^2.1.5" | ||
} | ||
} |
@@ -37,8 +37,9 @@ # Common background jobs library | ||
Both queue and worker is automatically started when you instantiate the processor. There is a default configuration which | ||
you can override by passing `queueConfig.queueOptions` and `workerOptions` params to the constructor. | ||
By default, both queue and worker are automatically started when you instantiate the processor. There is a default configuration which | ||
you can override by passing `queueOptions` and `workerOptions` params to the constructor. | ||
If you wish to only enable your processor to interact with the queue, but not process any jobs, you can set the `workerAutoRunEnabled` param to `false` in the constructor, which equals to setting `autorun` to `false` in `workerOptions`. While you'd normally want the worker to always be running, there are particular occasions where it is advisable to not start it automatically. This is the case when, for example, you are starting a separate instance of your application to schedule a job, but do not want for this instance to start processing this or any other job in the queue because they should be instead picked up by the main instance. | ||
Use `dispose()` to correctly stop processing any new messages and wait for the current ones to finish. | ||
### Spies | ||
@@ -45,0 +46,0 @@ |
74684
1402
212