Skip to content
Merged
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
10 changes: 5 additions & 5 deletions src/storage/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ export class FileStorage implements Storage {

async getJobStates (ids: string[]): Promise<Map<string, string | null>> {
const result = new Map<string, string | null>()
await Promise.all(
ids.map(async id => {
result.set(id, await this.getJobState(id))
})
)

for (const id of ids) {
result.set(id, await this.getJobState(id))
}

return result
}

Expand Down
34 changes: 33 additions & 1 deletion test/file-storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { setTimeout as sleep } from 'node:timers/promises'
import { createFileStorage } from './fixtures/file.ts'
import { type FileStorage } from '../src/storage/file.ts'
import { FileStorage } from '../src/storage/file.ts'
import { promisifyCallback } from './helpers/events.ts'

describe('FileStorage', () => {
Expand Down Expand Up @@ -122,6 +122,38 @@ describe('FileStorage', () => {
assert.strictEqual(states.get('job-2'), 'processing:2')
assert.strictEqual(states.get('job-3'), null)
})

it('should call getJobState from getJobStates sequentially', async () => {
class TrackingFileStorage extends FileStorage {
getJobStateCalls = 0

async getJobState (id: string): Promise<string | null> {
this.getJobStateCalls++
return super.getJobState(id)
}
}

const basePath = await mkdtemp(join(tmpdir(), 'job-queue-file-test-'))
const trackingStorage = new TrackingFileStorage({ basePath })

try {
await trackingStorage.connect()
await trackingStorage.setJobState('job-1', 'queued:1')
await trackingStorage.setJobState('job-2', 'processing:2')

const ids = ['job-1', 'job-2', 'job-3']
const states = await trackingStorage.getJobStates(ids)

assert.strictEqual(states.get('job-1'), 'queued:1')
assert.strictEqual(states.get('job-2'), 'processing:2')
assert.strictEqual(states.get('job-3'), null)
assert.strictEqual(trackingStorage.getJobStateCalls, ids.length)
} finally {
await trackingStorage.clear()
await trackingStorage.disconnect()
await rm(basePath, { recursive: true, force: true })
}
})
})

describe('requeue', () => {
Expand Down