diff --git a/.editorconfig b/.editorconfig index bf657a0..517cc06 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_size = 2 -indent_style = tab +indent_style = space end_of_line = lf charset = utf-8 trim_trailing_whitespace = true diff --git a/.npmignore b/.npmignore index 225554a..c8f723f 100644 --- a/.npmignore +++ b/.npmignore @@ -9,4 +9,3 @@ benchmarks .idea bin out -.nyc_output diff --git a/.prettierrc b/.prettierrc index f08a117..4ee4e6a 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,7 +2,7 @@ "trailingComma": "es5", "semi": false, "singleQuote": true, - "useTabs": true, + "useTabs": false, "quoteProps": "consistent", "bracketSpacing": true, "arrowParens": "always", diff --git a/adonis-typings/bull.ts b/adonis-typings/bull.ts index 494e084..86bfb91 100644 --- a/adonis-typings/bull.ts +++ b/adonis-typings/bull.ts @@ -1,37 +1,37 @@ declare module '@ioc:Rocketseat/Bull' { - import { Queue, Processor, JobsOptions, QueueOptions, WorkerOptions, Job } from 'bullmq' + import { Queue, Processor, JobsOptions, QueueOptions, WorkerOptions, Job } from 'bullmq' - export interface JobContract { - key: string - options?: JobsOptions - workerOptions?: WorkerOptions - queueOptions?: QueueOptions - concurrency?: number - handle(data: T): Promise - boot?: (queue: Queue) => void - } + export interface JobContract { + key: string + options?: JobsOptions + workerOptions?: WorkerOptions + queueOptions?: QueueOptions + concurrency?: number + handle(data: T): Promise + boot?: (queue: Queue) => void + } - export interface QueueContract extends JobContract { - bull: Queue - } + export interface QueueContract extends JobContract { + bull: Queue + } - export interface BullManagerContract { - queues: { [key: string]: QueueContract } + export interface BullManagerContract { + queues: { [key: string]: QueueContract } - getByKey(key: string): QueueContract + getByKey(key: string): QueueContract - add(name: string, data: T, jobOptions?: JobsOptions): Promise> + add(name: string, data: T, jobOptions?: JobsOptions): Promise> - remove(name: string, jobId: string): Promise + remove(name: string, jobId: string): Promise - ui(port?: number): void + ui(port?: number): void - shutdown(): Promise + shutdown(): Promise - process(): void - } + process(): void + } - const Bull: BullManagerContract + const Bull: BullManagerContract - export default Bull + export default Bull } diff --git a/commands/Listen.ts b/commands/Listen.ts index b0be85a..a37cd52 100644 --- a/commands/Listen.ts +++ b/commands/Listen.ts @@ -3,32 +3,32 @@ import { ApplicationContract } from '@ioc:Adonis/Core/Application' import { BullManagerContract } from '@ioc:Rocketseat/Bull' export default class Listen extends BaseCommand { - public static commandName = 'bull:listen' - public static description = 'Start the Bull listener' - constructor(app: ApplicationContract, kernel: Kernel, private bull: BullManagerContract) { - super(app, kernel) - } + public static commandName = 'bull:listen' + public static description = 'Start the Bull listener' + constructor(app: ApplicationContract, kernel: Kernel, private bull: BullManagerContract) { + super(app, kernel) + } - /** - * Start the bull-board - */ - @flags.boolean({ description: "Run bull's dashboard", alias: 'b' }) - public board: boolean + /** + * Start the bull-board + */ + @flags.boolean({ description: "Run bull's dashboard", alias: 'b' }) + public board: boolean - /** - * Custom port for the bull-board - */ - @flags.number({ description: "Run bull's dashboard in the provided port", alias: 'p' }) - public port?: number + /** + * Custom port for the bull-board + */ + @flags.number({ description: "Run bull's dashboard in the provided port", alias: 'p' }) + public port?: number - /** - * Execute command - */ - public async handle(): Promise { - this.bull.process() + /** + * Execute command + */ + public async handle(): Promise { + this.bull.process() - if (this.board || (typeof this.board === 'undefined' && typeof this.port !== 'undefined')) { - this.bull.ui(this.port) - } - } + if (this.board || (typeof this.board === 'undefined' && typeof this.port !== 'undefined')) { + this.bull.ui(this.port) + } + } } diff --git a/commands/MakeJob.ts b/commands/MakeJob.ts index c7c54fe..aaed69a 100644 --- a/commands/MakeJob.ts +++ b/commands/MakeJob.ts @@ -2,30 +2,30 @@ import { join } from 'path' import { BaseCommand, args } from '@adonisjs/ace' export default class MakeJob extends BaseCommand { - public static commandName = 'make:job' - public static description = 'Make a new Bull job' + public static commandName = 'make:job' + public static description = 'Make a new Bull job' - /** - * The name of the job file. - */ - @args.string({ description: 'Name of the job class' }) - public name: string + /** + * The name of the job file. + */ + @args.string({ description: 'Name of the job class' }) + public name: string - /** - * Execute command - */ - public async handle(): Promise { - const stub = join(__dirname, '..', 'templates', 'job.txt') + /** + * Execute command + */ + public async handle(): Promise { + const stub = join(__dirname, '..', 'templates', 'job.txt') - const path = this.application.resolveNamespaceDirectory('jobs') + const path = this.application.resolveNamespaceDirectory('jobs') - this.generator - .addFile(this.name, { pattern: 'pascalcase', form: 'singular' }) - .stub(stub) - .destinationDir(path || 'app/Jobs') - .useMustache() - .appRoot(this.application.cliCwd || this.application.appRoot) + this.generator + .addFile(this.name, { pattern: 'pascalcase', form: 'singular' }) + .stub(stub) + .destinationDir(path || 'app/Jobs') + .useMustache() + .appRoot(this.application.cliCwd || this.application.appRoot) - await this.generator.run() - } + await this.generator.run() + } } diff --git a/npm-audit.html b/npm-audit.html index 109b09d..5b094af 100644 --- a/npm-audit.html +++ b/npm-audit.html @@ -55,7 +55,7 @@
- September 7th 2020, 1:20:50 am + September 7th 2020, 1:48:10 am

Last updated

diff --git a/package.json b/package.json index 9843ddf..60a3534 100644 --- a/package.json +++ b/package.json @@ -16,10 +16,9 @@ "mrm": "mrm --preset=@adonisjs/mrm-preset", "pretest": "npm run lint", "test:docker": "docker-compose build && docker-compose run --rm tests", - "test:local": "node japaFile.js", - "test": "nyc npm run test:local", + "test": "node japaFile.js", "coverage:local": "nyc npm run test", - "coverage": "nyc report --reporter=text-lcov | coveralls", + "coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls", "clean": "del build", "copyfiles": "copyfiles \"templates/**/*.txt\" build", "compile": "npm run lint && npm run clean && tsc", diff --git a/providers/BullProvider.ts b/providers/BullProvider.ts index a3dbf1d..30322e3 100644 --- a/providers/BullProvider.ts +++ b/providers/BullProvider.ts @@ -5,28 +5,28 @@ import { BullManagerContract } from '@ioc:Rocketseat/Bull' * Provider to bind bull to the container */ export default class BullProvider { - constructor(protected container: IocContract) {} + constructor(protected container: IocContract) {} - public register() { - this.container.singleton('Rocketseat/Bull', () => { - const app = this.container.use('Adonis/Core/Application') - const Logger = this.container.use('Adonis/Core/Logger') - const Redis = this.container.use('Adonis/Addons/Redis') + public register() { + this.container.singleton('Rocketseat/Bull', () => { + const app = this.container.use('Adonis/Core/Application') + const Logger = this.container.use('Adonis/Core/Logger') + const Redis = this.container.use('Adonis/Addons/Redis') - const jobs = require(app.startPath('jobs'))?.default || [] - const { BullManager } = require('../src/BullManager') + const jobs = require(app.startPath('jobs'))?.default || [] + const { BullManager } = require('../src/BullManager') - return new BullManager(this.container, Logger, Redis, jobs) - }) + return new BullManager(this.container, Logger, Redis, jobs) + }) - this.container.alias('Rocketseat/Bull', 'Bull') - } + this.container.alias('Rocketseat/Bull', 'Bull') + } - public async boot() {} + public async boot() {} - public async ready() {} + public async ready() {} - public async shutdown() { - await this.container.use('Rocketseat/Bull').shutdown() - } + public async shutdown() { + await this.container.use('Rocketseat/Bull').shutdown() + } } diff --git a/src/BullManager.ts b/src/BullManager.ts index 91b9d61..562e8e3 100644 --- a/src/BullManager.ts +++ b/src/BullManager.ts @@ -6,110 +6,110 @@ import * as BullBoard from 'bull-board' import { RedisManagerContract } from '@ioc:Adonis/Addons/Redis' export class BullManager implements BullManagerContract { - constructor( - protected container: IocContract, - protected Logger: LoggerContract, - protected Redis: RedisManagerContract, - protected jobs: string[] - ) {} + constructor( + protected container: IocContract, + protected Logger: LoggerContract, + protected Redis: RedisManagerContract, + protected jobs: string[] + ) {} - private _queues: { [key: string]: QueueContract } - private _shutdowns: (() => Promise)[] = [] + private _queues: { [key: string]: QueueContract } + private _shutdowns: (() => Promise)[] = [] - public get queues() { - if (this._queues) { - return this._queues - } + public get queues() { + if (this._queues) { + return this._queues + } - this._queues = this.jobs.reduce((queues, path) => { - const jobDefinition: JobContract = this.container.make(path) + this._queues = this.jobs.reduce((queues, path) => { + const jobDefinition: JobContract = this.container.make(path) - queues[jobDefinition.key] = { - bull: new Queue(jobDefinition.key, { - connection: this.Redis as any, - ...jobDefinition.queueOptions, - }), - ...jobDefinition, - } + queues[jobDefinition.key] = { + bull: new Queue(jobDefinition.key, { + connection: this.Redis as any, + ...jobDefinition.queueOptions, + }), + ...jobDefinition, + } - return queues - }, {}) + return queues + }, {}) - return this.queues - } + return this.queues + } - public getByKey(key: string): QueueContract { - return this.queues[key] - } + public getByKey(key: string): QueueContract { + return this.queues[key] + } - public add(key: string, data: T, jobOptions?: JobsOptions): Promise> { - return this.getByKey(key).bull.add(key, data, jobOptions) - } + public add(key: string, data: T, jobOptions?: JobsOptions): Promise> { + return this.getByKey(key).bull.add(key, data, jobOptions) + } - public schedule(key: string, data: T, date: number | Date, options?: JobsOptions) { - const delay = typeof date === 'number' ? date : date.getTime() - Date.now() + public schedule(key: string, data: T, date: number | Date, options?: JobsOptions) { + const delay = typeof date === 'number' ? date : date.getTime() - Date.now() - if (delay <= 0) { - throw new Error('Invalid schedule time') - } + if (delay <= 0) { + throw new Error('Invalid schedule time') + } - return this.add(key, data, { ...options, delay }) - } + return this.add(key, data, { ...options, delay }) + } - public async remove(key: string, jobId: string): Promise { - const job = await this.getByKey(key).bull.getJob(jobId) - return job?.remove() - } + public async remove(key: string, jobId: string): Promise { + const job = await this.getByKey(key).bull.getJob(jobId) + return job?.remove() + } - public ui(port = 9999) { - BullBoard.setQueues(Object.keys(this.queues).map((key) => this.getByKey(key).bull)) + public ui(port = 9999) { + BullBoard.setQueues(Object.keys(this.queues).map((key) => this.getByKey(key).bull)) - const server = BullBoard.router.listen(port, () => { - this.Logger.info(`bull board on http://localhost:${port}`) - }) + const server = BullBoard.router.listen(port, () => { + this.Logger.info(`bull board on http://localhost:${port}`) + }) - const shutdown = async () => { - await server.close(() => { - this.Logger.info('Stopping bull board server') - }) - } + const shutdown = async () => { + await server.close(() => { + this.Logger.info('Stopping bull board server') + }) + } - this._shutdowns = [...this._shutdowns, shutdown] - } + this._shutdowns = [...this._shutdowns, shutdown] + } - public process() { - this.Logger.info('Queue processing started') + public process() { + this.Logger.info('Queue processing started') - const shutdowns = Object.keys(this.queues).map((key) => { - const queue = this.getByKey(key) + const shutdowns = Object.keys(this.queues).map((key) => { + const queue = this.getByKey(key) - if (typeof queue.boot !== 'undefined') { - queue.boot(queue.bull) - } + if (typeof queue.boot !== 'undefined') { + queue.boot(queue.bull) + } - const workerOptions: WorkerOptions = { - concurrency: queue.concurrency ?? 1, - connection: this.Redis as any, - ...queue.workerOptions, - } + const workerOptions: WorkerOptions = { + concurrency: queue.concurrency ?? 1, + connection: this.Redis as any, + ...queue.workerOptions, + } - const processor = async (job: BullJob) => { - await queue.handle(job) - } + const processor = async (job: BullJob) => { + await queue.handle(job) + } - const worker = new Worker(key, processor, workerOptions) + const worker = new Worker(key, processor, workerOptions) - const shutdown = () => Promise.all([queue.bull.close(), worker.close()]) + const shutdown = () => Promise.all([queue.bull.close(), worker.close()]) - return shutdown - }) + return shutdown + }) - this._shutdowns = [...this._shutdowns, ...shutdowns] + this._shutdowns = [...this._shutdowns, ...shutdowns] - return this - } + return this + } - public async shutdown() { - await Promise.all(this._shutdowns.map((shutdown) => shutdown())) - } + public async shutdown() { + await Promise.all(this._shutdowns.map((shutdown) => shutdown())) + } } diff --git a/templates/job.txt b/templates/job.txt index 1c07632..71e6bd4 100644 --- a/templates/job.txt +++ b/templates/job.txt @@ -1,22 +1,22 @@ import { JobContract } from '@ioc:Rocketseat/Bull' export default class {{ filename }} implements JobContract { - public key = '{{ filename }}' + public key = '{{ filename }}' - // public options = {} + // public options = {} - // public queueOptions = {} + // public queueOptions = {} - // public workerOptions = {} + // public workerOptions = {} - // public concurrency = 1 + // public concurrency = 1 - public async handle(job) { - const { data } = job - // Do somethign with you job data - } + public async handle(job) { + const { data } = job + // Do somethign with you job data + } - // public boot(queue) { - // // Fired before start process - // } + // public boot(queue) { + // // Fired before start process + // } } diff --git a/test/functional/app/SomeJob.js b/test/functional/app/SomeJob.js index eb783f0..f624158 100644 --- a/test/functional/app/SomeJob.js +++ b/test/functional/app/SomeJob.js @@ -1,11 +1,11 @@ class SomeJob { - static get key() { - return 'SomeJob-key' - } + static get key() { + return 'SomeJob-key' + } - async handle() { - return 'good luck' - } + async handle() { + return 'good luck' + } } module.exports = SomeJob diff --git a/test/functional/providers.spec.ts b/test/functional/providers.spec.ts index df57e7a..2fc260e 100644 --- a/test/functional/providers.spec.ts +++ b/test/functional/providers.spec.ts @@ -9,37 +9,37 @@ import { RedisManager } from '@adonisjs/redis/build/src/RedisManager' import { Emitter } from '@adonisjs/events/build/standalone' test.group('Provider', () => { - test('BullProvider', async (assert) => { - const ioc = new Ioc() + test('BullProvider', async (assert) => { + const ioc = new Ioc() - ioc.bind('Adonis/Core/Logger', () => console) - ioc.bind('Adonis/Core/Application', () => { - return new Application(__dirname, ioc, {}, {}) - }) - ioc.bind('Adonis/Addons/Redis', () => { - return new RedisManager( - ioc, - { - connection: 'primary', - connections: { - primary: { - host: process.env.REDIS_HOST, - port: Number(process.env.REDIS_PORT), - healthCheck: true, - }, - }, - } as any, - new Emitter(ioc) - ) - }) + ioc.bind('Adonis/Core/Logger', () => console) + ioc.bind('Adonis/Core/Application', () => { + return new Application(__dirname, ioc, {}, {}) + }) + ioc.bind('Adonis/Addons/Redis', () => { + return new RedisManager( + ioc, + { + connection: 'primary', + connections: { + primary: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + healthCheck: true, + }, + }, + } as any, + new Emitter(ioc) + ) + }) - const registrar = new Registrar(ioc, join(__dirname, '../../')) - await registrar.useProviders(['./providers/BullProvider']).registerAndBoot() + const registrar = new Registrar(ioc, join(__dirname, '../../')) + await registrar.useProviders(['./providers/BullProvider']).registerAndBoot() - await registrar.boot() + await registrar.boot() - assert.instanceOf(ioc.use('Rocketseat/Bull'), BullManager) - assert.deepEqual(ioc.use('Rocketseat/Bull'), ioc.use('Rocketseat/Bull')) - assert.deepEqual(ioc.use('Rocketseat/Bull'), ioc.use('Bull')) - }) + assert.instanceOf(ioc.use('Rocketseat/Bull'), BullManager) + assert.deepEqual(ioc.use('Rocketseat/Bull'), ioc.use('Rocketseat/Bull')) + assert.deepEqual(ioc.use('Rocketseat/Bull'), ioc.use('Bull')) + }) }) diff --git a/test/unit/queue.spec.ts b/test/unit/queue.spec.ts index db385db..0402ae3 100644 --- a/test/unit/queue.spec.ts +++ b/test/unit/queue.spec.ts @@ -10,152 +10,152 @@ import { RedisManagerContract } from '@ioc:Adonis/Addons/Redis' import { LoggerContract } from '@ioc:Adonis/Core/Logger' test.group('Bull', () => { - test('should add a new job', async (assert) => { - const ioc = new Ioc() - - ioc.bind('App/Jobs/TestBull', () => ({ - key: 'TestBull-name', - concurrency: 2, - async handle() {}, - })) - - const redis = (new RedisManager( - ioc, - { - connection: 'primary', - connections: { - primary: { - host: process.env.REDIS_HOST, - port: Number(process.env.REDIS_PORT), - healthCheck: true, - }, - }, - } as any, - new Emitter(ioc) - ) as unknown) as RedisManagerContract - - const logger = (new FakeLogger({} as any) as unknown) as LoggerContract - - const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) - const jobDefinition = ioc.use('App/Jobs/TestBull') - const data = { test: 'data' } - - const queue = bull.getByKey(jobDefinition.key) - const job = await bull.add(jobDefinition.key, data) - - assert.isDefined(job) - assert.equal(jobDefinition.key, job.name) - assert.deepEqual(data, job.data) - assert.equal(queue.concurrency, 2) - - await redis.quit('primary') - }) - - test('should add a new job with events inside Job class', async (assert) => { - const ioc = new Ioc() - assert.plan(1) - - ioc.bind('App/Jobs/TestBull', () => ({ - key: 'TestBull-name', - concurrency: 2, - async handle() {}, - boot(queue) { - assert.isOk(queue) - }, - })) - - const redis = (new RedisManager( - ioc, - { - connection: 'primary', - connections: { - primary: { - host: process.env.REDIS_HOST, - port: Number(process.env.REDIS_PORT), - healthCheck: true, - }, - }, - } as any, - new Emitter(ioc) - ) as unknown) as RedisManagerContract - - const logger = (new FakeLogger({} as any) as unknown) as LoggerContract - - const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) - const jobDefinition = ioc.use('App/Jobs/TestBull') - const data = { test: 'data' } - - bull.add(jobDefinition.key, data) - bull.process() - }) - - test('should schedule a new job', async (assert) => { - const ioc = new Ioc() - - ioc.bind('App/Jobs/TestBull', () => ({ - key: 'TestBull-name', - async handle() {}, - })) - - const redis = (new RedisManager( - ioc, - { - connection: 'primary', - connections: { - primary: { - host: process.env.REDIS_HOST, - port: Number(process.env.REDIS_PORT), - healthCheck: true, - }, - }, - } as any, - new Emitter(ioc) - ) as unknown) as RedisManagerContract - - const logger = (new FakeLogger({} as any) as unknown) as LoggerContract - - const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) - const jobDefinition = ioc.use('App/Jobs/TestBull') - const data = { test: 'data' } - - const job = await bull.schedule(jobDefinition.key, data, 1000) - - assert.equal(jobDefinition.key, job.name) - assert.equal(job.opts.delay, 1000) - assert.deepEqual(data, job.data) - }) - - test("shouldn't schedule when time is invalid", async (assert) => { - const ioc = new Ioc() - - ioc.bind('App/Jobs/TestBull', () => ({ - key: 'TestBull-name', - async handle() {}, - })) - - const redis = (new RedisManager( - ioc, - { - connection: 'primary', - connections: { - primary: { - host: process.env.REDIS_HOST, - port: Number(process.env.REDIS_PORT), - healthCheck: true, - }, - }, - } as any, - new Emitter(ioc) - ) as unknown) as RedisManagerContract - - const logger = (new FakeLogger({} as any) as unknown) as LoggerContract - - const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) - const jobDefinition = ioc.use('App/Jobs/TestBull') - const data = { test: 'data' } - - assert.throw(() => { - bull.schedule(jobDefinition.key, data, -100) - }, 'Invalid schedule time') - }) + test('should add a new job', async (assert) => { + const ioc = new Ioc() + + ioc.bind('App/Jobs/TestBull', () => ({ + key: 'TestBull-name', + concurrency: 2, + async handle() {}, + })) + + const redis = (new RedisManager( + ioc, + { + connection: 'primary', + connections: { + primary: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + healthCheck: true, + }, + }, + } as any, + new Emitter(ioc) + ) as unknown) as RedisManagerContract + + const logger = (new FakeLogger({} as any) as unknown) as LoggerContract + + const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) + const jobDefinition = ioc.use('App/Jobs/TestBull') + const data = { test: 'data' } + + const queue = bull.getByKey(jobDefinition.key) + const job = await bull.add(jobDefinition.key, data) + + assert.isDefined(job) + assert.equal(jobDefinition.key, job.name) + assert.deepEqual(data, job.data) + assert.equal(queue.concurrency, 2) + + await redis.quit('primary') + }) + + test('should add a new job with events inside Job class', async (assert) => { + const ioc = new Ioc() + assert.plan(1) + + ioc.bind('App/Jobs/TestBull', () => ({ + key: 'TestBull-name', + concurrency: 2, + async handle() {}, + boot(queue) { + assert.isOk(queue) + }, + })) + + const redis = (new RedisManager( + ioc, + { + connection: 'primary', + connections: { + primary: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + healthCheck: true, + }, + }, + } as any, + new Emitter(ioc) + ) as unknown) as RedisManagerContract + + const logger = (new FakeLogger({} as any) as unknown) as LoggerContract + + const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) + const jobDefinition = ioc.use('App/Jobs/TestBull') + const data = { test: 'data' } + + bull.add(jobDefinition.key, data) + bull.process() + }) + + test('should schedule a new job', async (assert) => { + const ioc = new Ioc() + + ioc.bind('App/Jobs/TestBull', () => ({ + key: 'TestBull-name', + async handle() {}, + })) + + const redis = (new RedisManager( + ioc, + { + connection: 'primary', + connections: { + primary: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + healthCheck: true, + }, + }, + } as any, + new Emitter(ioc) + ) as unknown) as RedisManagerContract + + const logger = (new FakeLogger({} as any) as unknown) as LoggerContract + + const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) + const jobDefinition = ioc.use('App/Jobs/TestBull') + const data = { test: 'data' } + + const job = await bull.schedule(jobDefinition.key, data, 1000) + + assert.equal(jobDefinition.key, job.name) + assert.equal(job.opts.delay, 1000) + assert.deepEqual(data, job.data) + }) + + test("shouldn't schedule when time is invalid", async (assert) => { + const ioc = new Ioc() + + ioc.bind('App/Jobs/TestBull', () => ({ + key: 'TestBull-name', + async handle() {}, + })) + + const redis = (new RedisManager( + ioc, + { + connection: 'primary', + connections: { + primary: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + healthCheck: true, + }, + }, + } as any, + new Emitter(ioc) + ) as unknown) as RedisManagerContract + + const logger = (new FakeLogger({} as any) as unknown) as LoggerContract + + const bull = new BullManager(ioc, logger, redis, ['App/Jobs/TestBull']) + const jobDefinition = ioc.use('App/Jobs/TestBull') + const data = { test: 'data' } + + assert.throw(() => { + bull.schedule(jobDefinition.key, data, -100) + }, 'Invalid schedule time') + }) })