Skip to content

Commit d2548ce

Browse files
committed
chore: initial commit
0 parents  commit d2548ce

43 files changed

Lines changed: 8320 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build
2+
build
3+
4+
# Node & Dependencies
5+
node_modules
6+
coverage
7+
8+
# Build tools specific
9+
.yarn/*
10+
!.yarn/patches
11+
!.yarn/plugins
12+
!.yarn/releases
13+
!.yarn/sdks
14+
!.yarn/versions
15+
npm-debug.log
16+
yarn-error.log
17+
18+
# Editors specific
19+
.fleet
20+
.idea
21+
.vscode

.yarnrc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

LICENSE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# The MIT License
2+
3+
Copyright 2025 Romain Lanz, contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Whitespace-only changes.

bin/test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { configure, processCLIArgs, run } from '@japa/runner'
2+
import { assert } from '@japa/assert'
3+
import { fileSystem } from '@japa/file-system'
4+
import { expectTypeOf } from '@japa/expect-type'
5+
6+
processCLIArgs(process.argv.splice(2))
7+
configure({
8+
files: ['tests/**/*.spec.ts'],
9+
plugins: [assert(), fileSystem(), expectTypeOf()],
10+
})
11+
12+
void run()

compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
redis:
3+
image: redis:alpine
4+
ports:
5+
- "6379:6379"

eslint.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { configPkg } from '@adonisjs/eslint-config'
2+
3+
export default configPkg({
4+
ignores: ['coverage'],
5+
})

examples/app.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { config } from './config.ts'
2+
import { QueueManager } from '#src/queue_manager'
3+
import SendEmailJob from './jobs/send_email_job.ts'
4+
import SyncJob from './jobs/sync_job.ts'
5+
6+
await QueueManager.init(config)
7+
8+
await SendEmailJob.dispatch({ to: 'julien@ripouteau.com' }).in('1s')
9+
10+
await SyncJob.dispatch({ source: 'remote_api' }).in('2s')
11+
12+
for (let i = 0; i < 10; i++) {
13+
await SendEmailJob.dispatch({ to: 'romain.lanz@pm.me' + i })
14+
}
15+
16+
await QueueManager.destroy()

examples/config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { QueueManagerConfig } from '#types/main'
2+
import { Redis } from 'ioredis'
3+
import { redis } from '#drivers/redis_adapter'
4+
import { sync } from '#drivers/sync_adapter'
5+
6+
export const redisConnection = new Redis({
7+
host: 'localhost',
8+
port: 6379,
9+
keyPrefix: 'boringnode::queue::',
10+
db: 0,
11+
})
12+
13+
export const config: QueueManagerConfig = {
14+
default: 'redis',
15+
16+
adapters: {
17+
sync: sync(),
18+
redis: redis(redisConnection),
19+
},
20+
21+
worker: {
22+
concurrency: 5,
23+
pollingInterval: '10ms',
24+
},
25+
26+
locations: ['./examples/jobs/**/*.ts'],
27+
}

examples/jobs/send_email_job.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { setTimeout } from 'node:timers/promises'
2+
import { Job } from '#src/job'
3+
import type { JobOptions } from '#types/main'
4+
5+
interface SendEmailPayload {
6+
to: string
7+
}
8+
9+
export default class SendEmailJob extends Job<SendEmailPayload> {
10+
static readonly jobName = 'SendEmailJob'
11+
12+
static options: JobOptions = {
13+
queue: 'email',
14+
}
15+
16+
async execute(): Promise<void> {
17+
await setTimeout(1000)
18+
console.log(`Sending email to: ${this.payload.to}`)
19+
}
20+
}

0 commit comments

Comments
 (0)