Skip to content

Commit

Permalink
feat(core): Make DefaultJobQueuePlugin configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Mar 23, 2021
1 parent b01e888 commit 6373d9f
Showing 1 changed file with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,41 @@ import { SqlJobQueueStrategy } from './sql-job-queue-strategy';
* };
* ```
*
* ## Configuration
*
* It is possible to configure the behaviour of the {@link SqlJobQueueStrategy} by passing options to the static `init()` function:
*
* @example
* ```TypeScript
* export const config: VendureConfig = {
* plugins: [
* DefaultJobQueuePlugin.init({
* // The interval in ms between polling for new jobs. The default is 200ms.
* // Using a longer interval reduces load on the database but results in a slight
* // delay in processing jobs.
* pollInterval: 5000,
* // The number of jobs to process concurrently per worker. Defaults to 1.
* concurrency: 2
* }),
* ],
* };
* ```
*
* @docsCategory JobQueue
*/
@VendurePlugin({
imports: [PluginCommonModule],
entities: [JobRecord],
configuration: config => {
config.jobQueueOptions.jobQueueStrategy = new SqlJobQueueStrategy();
const { pollInterval, concurrency } = DefaultJobQueuePlugin.options ?? {};
config.jobQueueOptions.jobQueueStrategy = new SqlJobQueueStrategy(concurrency, pollInterval);
return config;
},
})
export class DefaultJobQueuePlugin {}
export class DefaultJobQueuePlugin {
static options: { pollInterval?: number; concurrency?: number };
static init(options: { pollInterval?: number; concurrency?: number }) {
DefaultJobQueuePlugin.options = options;
return DefaultJobQueuePlugin;
}
}

0 comments on commit 6373d9f

Please sign in to comment.