Skip to content

Commit 5c0f353

Browse files
committed
refactor: Switch to esm setup
contributes to #546
1 parent b745452 commit 5c0f353

53 files changed

Lines changed: 10130 additions & 7944 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
.vscode
44
*.tgz
55
*.log
6-
coverage
6+
coverage
7+
dist

.nvmrc

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

examples/load/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const PgBoss = require('../../src')
55
const SCHEMA_COUNT = 60
66
const QUEUE_COUNT = 200
77

8-
loadTest()
9-
.catch(err => {
10-
console.log(err)
11-
process.exit(1)
12-
})
8+
loadTest().catch((err) => {
9+
console.log(err)
10+
process.exit(1)
11+
})
1312

1413
async function loadTest () {
15-
const schemas = new Array(SCHEMA_COUNT).fill(null).map((_, index) => `schema${index}`)
14+
const schemas = new Array(SCHEMA_COUNT)
15+
.fill(null)
16+
.map((_, index) => `schema${index}`)
1617

1718
for (const schema of schemas) {
1819
setImmediate(() => init(schema))
@@ -21,31 +22,40 @@ async function loadTest () {
2122

2223
async function init (schema) {
2324
const config = helper.getConfig()
24-
const boss = new PgBoss({ ...config, schema, supervise: false, schedule: false })
25+
const boss = new PgBoss({
26+
...config,
27+
schema,
28+
supervise: false,
29+
schedule: false
30+
})
2531

2632
boss.on('error', console.error)
2733

2834
await boss.start()
2935

3036
console.log('creating queues')
3137

32-
const queues = new Array(QUEUE_COUNT).fill(null).map((_, index) => `queue${index}`)
38+
const queues = new Array(QUEUE_COUNT)
39+
.fill(null)
40+
.map((_, index) => `queue${index}`)
3341

3442
for (const queue of queues) {
3543
console.log(`creating queue ${schema}.${queue}`)
3644
await boss.createQueue(queue)
37-
await boss.work(queue, () => {})
45+
await boss.work(queue, () => { })
3846
}
3947

4048
console.log('created queues')
4149

4250
while (true) {
4351
console.log(`${schema}: sending a job to each one: ${new Date()}`)
4452

45-
await Promise.all(queues.map(async queue => {
46-
await boss.send(queue)
47-
await boss.fetch(queue)
48-
}))
53+
await Promise.all(
54+
queues.map(async (queue) => {
55+
await boss.send(queue)
56+
await boss.fetch(queue)
57+
})
58+
)
4959

5060
await delay(1000)
5161
}

examples/readme.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const helper = require('../test/testHelper')
1+
import { getConnectionString } from '../test/testHelper.js'
2+
import PgBoss from '../src/index.js'
23

34
async function readme () {
4-
const PgBoss = require('../src')
5-
const boss = new PgBoss(helper.getConnectionString())
5+
const boss = new PgBoss(getConnectionString())
66

77
boss.on('error', console.error)
88

@@ -21,8 +21,7 @@ async function readme () {
2121
})
2222
}
2323

24-
readme()
25-
.catch(err => {
26-
console.log(err)
27-
process.exit(1)
28-
})
24+
readme().catch((err) => {
25+
console.log(err)
26+
process.exit(1)
27+
})

examples/schedule.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ async function schedule () {
1515
await boss.schedule(queue, '*/2 * * * *', { arg1: 'schedule me' })
1616

1717
await boss.work(queue, async ([job]) => {
18-
console.log(`received job ${job.id} with data ${JSON.stringify(job.data)} on ${new Date().toISOString()}`)
18+
console.log(
19+
`received job ${job.id} with data ${JSON.stringify(job.data)} on ${new Date().toISOString()}`
20+
)
1921
})
2022
}
2123

22-
schedule()
23-
.catch(err => {
24-
console.log(err)
25-
process.exit(1)
26-
})
24+
schedule().catch((err) => {
25+
console.log(err)
26+
process.exit(1)
27+
})

0 commit comments

Comments
 (0)