diff --git a/README.md b/README.md index 1fbcaaa..6c52ebb 100644 --- a/README.md +++ b/README.md @@ -361,16 +361,16 @@ const adapter = knex(config, 'custom_jobs_table')
-Database setup with QueueSchemaService +Database setup with KnexQueueSchemaService -The Knex adapter requires tables to be created before use. Use `QueueSchemaService` to create them: +The Knex adapter requires tables to be created before use. Use `KnexQueueSchemaService` to create them: ```typescript -import { QueueSchemaService } from '@boringnode/queue' +import { KnexQueueSchemaService } from '@boringnode/queue/drivers/knex_adapter' import Knex from 'knex' const connection = Knex({ client: 'pg', connection: '...' }) -const schemaService = new QueueSchemaService(connection) +const schemaService = new KnexQueueSchemaService(connection) // Create tables with default names await schemaService.createJobsTable() @@ -386,17 +386,17 @@ await schemaService.createJobsTable('queue_jobs', (table) => { ```typescript import { BaseSchema } from '@adonisjs/lucid/schema' -import { QueueSchemaService } from '@boringnode/queue' +import { KnexQueueSchemaService } from '@boringnode/queue/drivers/knex_adapter' export default class extends BaseSchema { async up() { - const schemaService = new QueueSchemaService(this.db.connection().getWriteClient()) + const schemaService = new KnexQueueSchemaService(this.db.connection().getWriteClient()) await schemaService.createJobsTable() await schemaService.createSchedulesTable() } async down() { - const schemaService = new QueueSchemaService(this.db.connection().getWriteClient()) + const schemaService = new KnexQueueSchemaService(this.db.connection().getWriteClient()) await schemaService.dropSchedulesTable() await schemaService.dropJobsTable() } diff --git a/index.ts b/index.ts index ac3860b..e1bd757 100644 --- a/index.ts +++ b/index.ts @@ -5,7 +5,6 @@ export { Locator } from './src/locator.js' export { Schedule } from './src/schedule.js' export { ScheduleBuilder } from './src/schedule_builder.js' export { JobBatchDispatcher } from './src/job_batch_dispatcher.js' -export { QueueSchemaService } from './src/services/queue_schema.js' export { customBackoff, linearBackoff, diff --git a/src/drivers/knex_adapter.ts b/src/drivers/knex_adapter.ts index 6f4e56e..1611a86 100644 --- a/src/drivers/knex_adapter.ts +++ b/src/drivers/knex_adapter.ts @@ -15,6 +15,8 @@ import type { import { DEFAULT_PRIORITY } from '../constants.js' import { calculateScore, resolveRetention } from '../utils.js' +export { KnexQueueSchemaService } from '../services/knex_queue_schema.js' + export interface KnexAdapterOptions { connection: Knex tableName?: string @@ -417,7 +419,7 @@ export class KnexAdapter implements Adapter { } catch (err) { if (this.#isMissingDedupColumn(err)) { throw new Error( - `Dedup columns missing on "${this.#jobsTable}". Run QueueSchemaService.addDedupColumns() on your jobs table before dispatching jobs with .dedup().`, + `Dedup columns missing on "${this.#jobsTable}". Run KnexQueueSchemaService.addDedupColumns() on your jobs table before dispatching jobs with .dedup().`, { cause: err } ) } diff --git a/src/services/queue_schema.ts b/src/services/knex_queue_schema.ts similarity index 99% rename from src/services/queue_schema.ts rename to src/services/knex_queue_schema.ts index 241c752..9e5da04 100644 --- a/src/services/queue_schema.ts +++ b/src/services/knex_queue_schema.ts @@ -1,6 +1,6 @@ import type { Knex } from 'knex' -export class QueueSchemaService { +export class KnexQueueSchemaService { #connection: Knex constructor(connection: Knex) { diff --git a/tests/adapter.spec.ts b/tests/adapter.spec.ts index d4d147d..ec7a6ce 100644 --- a/tests/adapter.spec.ts +++ b/tests/adapter.spec.ts @@ -4,7 +4,7 @@ import { Redis } from 'ioredis' import { MemoryAdapter } from './_mocks/memory_adapter.js' import { redis, RedisAdapter } from '../src/drivers/redis_adapter.js' import { KnexAdapter } from '../src/drivers/knex_adapter.js' -import { QueueSchemaService } from '../src/services/queue_schema.js' +import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js' import { registerDriverTestSuite } from './_utils/register_driver_test_suite.js' import { withRedisWriteSpy } from './_utils/with_redis_write_spy.js' import { withKnexQuerySpy } from './_utils/with_knex_query_spy.js' @@ -644,8 +644,8 @@ test.group('Adapter | Knex (SQLite)', (group) => { useNullAsDefault: true, }) - // Create tables via QueueSchemaService - const schemaService = new QueueSchemaService(connection) + // Create tables via KnexQueueSchemaService + const schemaService = new KnexQueueSchemaService(connection) await schemaService.createJobsTable() await schemaService.createSchedulesTable() @@ -728,7 +728,7 @@ test.group('Adapter | Knex (SQLite)', (group) => { test.group('Adapter | Knex (PostgreSQL)', (group) => { let connection: ReturnType let adapter: KnexAdapter - let schemaService: QueueSchemaService + let schemaService: KnexQueueSchemaService const tableName = 'queue_jobs_test' const schedulesTableName = 'queue_schedules_test' @@ -744,7 +744,7 @@ test.group('Adapter | Knex (PostgreSQL)', (group) => { }, }) - schemaService = new QueueSchemaService(connection) + schemaService = new KnexQueueSchemaService(connection) // Clean up tables before each test await schemaService.dropJobsTable(tableName) diff --git a/tests/worker_adapter.spec.ts b/tests/worker_adapter.spec.ts index 8b66e82..3be2b58 100644 --- a/tests/worker_adapter.spec.ts +++ b/tests/worker_adapter.spec.ts @@ -4,7 +4,7 @@ import { Redis } from 'ioredis' import { MemoryAdapter } from './_mocks/memory_adapter.js' import { RedisAdapter } from '../src/drivers/redis_adapter.js' import { KnexAdapter } from '../src/drivers/knex_adapter.js' -import { QueueSchemaService } from '../src/services/queue_schema.js' +import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js' import { registerWorkerRetryTestSuite } from './_utils/register_worker_retry_suite.js' const KEY_PREFIX = 'boringnode::queue::worker-test::' @@ -62,7 +62,7 @@ test.group('Worker Adapter | Knex (SQLite)', (group) => { useNullAsDefault: true, }) - const schemaService = new QueueSchemaService(connection) + const schemaService = new KnexQueueSchemaService(connection) await schemaService.createJobsTable() await schemaService.createSchedulesTable() @@ -84,7 +84,7 @@ test.group('Worker Adapter | Knex (SQLite)', (group) => { test.group('Worker Adapter | Knex (PostgreSQL)', (group) => { let connection: ReturnType let adapter: KnexAdapter - let schemaService: QueueSchemaService + let schemaService: KnexQueueSchemaService const tableName = 'queue_jobs_worker_test' const schedulesTableName = 'queue_schedules_worker_test' @@ -100,7 +100,7 @@ test.group('Worker Adapter | Knex (PostgreSQL)', (group) => { }, }) - schemaService = new QueueSchemaService(connection) + schemaService = new KnexQueueSchemaService(connection) await schemaService.dropJobsTable(tableName) await schemaService.dropSchedulesTable(schedulesTableName) await schemaService.createJobsTable(tableName) diff --git a/tests/worker_concurrency.spec.ts b/tests/worker_concurrency.spec.ts index 643b145..229f6a7 100644 --- a/tests/worker_concurrency.spec.ts +++ b/tests/worker_concurrency.spec.ts @@ -3,7 +3,7 @@ import { test } from '@japa/runner' import { Redis } from 'ioredis' import { RedisAdapter } from '../src/drivers/redis_adapter.js' import { KnexAdapter } from '../src/drivers/knex_adapter.js' -import { QueueSchemaService } from '../src/services/queue_schema.js' +import { KnexQueueSchemaService } from '../src/services/knex_queue_schema.js' import { registerWorkerConcurrencyTestSuite } from './_utils/register_worker_concurrency_suite.js' const KEY_PREFIX = 'boringnode::queue::concurrency-test::' @@ -38,7 +38,7 @@ test.group('Worker Concurrency | Redis', (group) => { test.group('Worker Concurrency | Knex (PostgreSQL)', (group) => { let connection: ReturnType let adapter: KnexAdapter - let schemaService: QueueSchemaService + let schemaService: KnexQueueSchemaService const tableName = 'queue_jobs_concurrency_test' const schedulesTableName = 'queue_schedules_concurrency_test' @@ -54,7 +54,7 @@ test.group('Worker Concurrency | Knex (PostgreSQL)', (group) => { }, }) - schemaService = new QueueSchemaService(connection) + schemaService = new KnexQueueSchemaService(connection) // Drop both tables to ensure clean state await schemaService.dropJobsTable(tableName)