Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ jobs:
--health-interval 1s
--health-timeout 3s
--health-retries 5
postgres:
image: postgres:17-alpine
ports:
- 5432:5432
env:
POSTGRES_DB: job_queue_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd "pg_isready -U postgres"
--health-interval 1s
--health-timeout 3s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ services:
interval: 1s
timeout: 3s
retries: 5

postgres:
image: postgres:17-alpine
ports:
- "127.0.0.1:5432:5432"
environment:
POSTGRES_DB: job_queue_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 1s
timeout: 3s
retries: 5
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
},
"optionalDependencies": {
"fast-write-atomic": "^0.4.0",
"iovalkey": "^0.2.0"
"iovalkey": "^0.2.0",
"pg": "^8.20.0"
},
"devDependencies": {
"@platformatic/flame": "^1.6.0",
Expand All @@ -64,4 +65,4 @@
"engines": {
"node": ">=22.19.0"
}
}
}
124 changes: 124 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type { Storage } from './storage/types.ts'
export { MemoryStorage } from './storage/memory.ts'
export { RedisStorage } from './storage/redis.ts'
export { FileStorage } from './storage/file.ts'
export { PgStorage } from './storage/pg.ts'

// Queue
export { Queue } from './queue.ts'
Expand Down
2 changes: 1 addition & 1 deletion src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Queue<TPayload, TResult = void> extends EventEmitter<QueueEvents<TR
constructor (config: QueueConfig<TPayload, TResult>) {
super()

this.#storage = config.storage
this.#storage = config.name ? config.storage.createNamespace(config.name) : config.storage
this.#workerId = config.workerId ?? randomUUID()
this.#payloadSerde = config.payloadSerde ?? createJsonSerde<TPayload>()
this.#resultSerde = config.resultSerde ?? createJsonSerde<TResult>()
Expand Down
3 changes: 2 additions & 1 deletion src/reaper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface LeaderElectionConfig {

interface ReaperConfig<TPayload> {
storage: Storage
name?: string
payloadSerde?: Serde<TPayload>
visibilityTimeout?: number
leaderElection?: LeaderElectionConfig
Expand Down Expand Up @@ -62,7 +63,7 @@ export class Reaper<TPayload> extends EventEmitter<ReaperEvents> {

constructor (config: ReaperConfig<TPayload>) {
super()
this.#storage = config.storage
this.#storage = config.name ? config.storage.createNamespace(config.name) : config.storage
this.#payloadSerde = config.payloadSerde ?? createJsonSerde<TPayload>()
this.#visibilityTimeout = config.visibilityTimeout ?? 30000
this.#leaderElection = config.leaderElection ?? { enabled: false }
Expand Down
4 changes: 4 additions & 0 deletions src/storage/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,10 @@ export class FileStorage implements Storage {
}
}

createNamespace (name: string): Storage {
return new FileStorage({ basePath: join(this.#basePath, name) })
}

/**
* Clear all data (useful for testing)
*/
Expand Down
4 changes: 4 additions & 0 deletions src/storage/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,10 @@ export class MemoryStorage implements Storage {
}
}

createNamespace (_name: string): Storage {
return new MemoryStorage()
}

/**
* Clear all data (useful for testing)
*/
Expand Down
Loading
Loading