a5d624166b
* feat(backgroundjobs): add new background jobs module for file imports queueing * fix(fileuploads): a merge gone wrong * feat(backgroundjobs): rename rhino queue env var * test(backgroundjob): use deep equal claude * fix(fileuploads): sync PR review * feat(backgroundjobs): add origin server url to the background jobs table * test(backgroundjobs): make tests pass
35 lines
858 B
TypeScript
35 lines
858 B
TypeScript
import {
|
|
BackgroundJob,
|
|
BackgroundJobConfig,
|
|
BackgroundJobPayload,
|
|
BackgroundJobStatus,
|
|
StoreBackgroundJob
|
|
} from '@/modules/backgroundjobs/domain'
|
|
import cryptoRandomString from 'crypto-random-string'
|
|
|
|
export const scheduleBackgroundJobFactory = <T extends BackgroundJobPayload>({
|
|
storeBackgroundJob,
|
|
jobConfig
|
|
}: {
|
|
storeBackgroundJob: StoreBackgroundJob
|
|
jobConfig: BackgroundJobConfig
|
|
}) => {
|
|
return async ({ jobPayload }: { jobPayload: T }): Promise<BackgroundJob<T>> => {
|
|
const jobId = cryptoRandomString({ length: 10 })
|
|
const job = {
|
|
...jobConfig,
|
|
attempt: 0,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date(),
|
|
id: jobId,
|
|
jobType: jobPayload.jobType,
|
|
payload: jobPayload,
|
|
status: BackgroundJobStatus.Queued
|
|
}
|
|
await storeBackgroundJob({
|
|
job
|
|
})
|
|
return job
|
|
}
|
|
}
|