Skip to content

Commit

Permalink
more fun test job
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheraff committed Jul 7, 2024
1 parent 4fbecb0 commit 897d7fb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions admin/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ type Event = object

const foo = new Job({
id: 'foo',
input: z.object({ k: z.number() }),
}, async ({ k }) => {
input: z.object({
k: z.number(),
date: z.string().datetime(),
parity: z.boolean().optional(),
}),
priority: () => Math.floor(Math.random() * 10),
}, async ({ k, parity }) => {
const iter = await Job.run('random-iter', () => Math.ceil(Math.random() * 10))
for (let i = 0; i < iter; i++) {
await Job.sleep(Math.random() * 8_000 + 2_000)
Expand All @@ -36,7 +41,10 @@ const foo = new Job({
])
}
await Job.sleep("5s")
Job.dispatch(foo, { k: k + 1 })
if (parity) {
Job.dispatch(foo, { k: k + 1, date: new Date().toISOString(), parity: false })
Job.dispatch(foo, { k: k + 1, date: new Date().toISOString(), parity: true })
}
return 2
})

Expand All @@ -48,7 +56,7 @@ const queue = new Queue({
jobs: { foo }
})

queue.jobs.foo.dispatch({ k: 0 })
queue.jobs.foo.dispatch({ k: 0, date: new Date().toISOString(), parity: true })

const tasksStmt = db.prepare<{ queue: string, origin: number }, Task>('SELECT * FROM tasks WHERE queue = @queue AND updated_at > @origin ORDER BY created_at ASC')
const stepsStmt = db.prepare<{ queue: string, origin: number }, Step>('SELECT * FROM steps WHERE queue = @queue AND updated_at > @origin ORDER BY created_at ASC')
Expand Down

0 comments on commit 897d7fb

Please sign in to comment.