File tree Expand file tree Collapse file tree 4 files changed +36
-6
lines changed
Expand file tree Collapse file tree 4 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ async function main() {
6565 cmd . make ( buddy )
6666 cmd . migrate ( buddy )
6767 cmd . outdated ( buddy )
68+ cmd . queue ( buddy )
6869 cmd . release ( buddy )
6970 cmd . route ( buddy )
7071 cmd . saas ( buddy )
Original file line number Diff line number Diff line change @@ -40,8 +40,6 @@ export interface JobOptions {
4040}
4141
4242export async function runJob ( name : string , options : JobOptions = { } ) : Promise < void > {
43- log . info ( `Running job: ${ name } ` )
44-
4543 try {
4644 const jobModule = await import ( appPath ( `Jobs/${ name } .ts` ) )
4745 const job = jobModule . default as JobConfig
Original file line number Diff line number Diff line change 1- import { Job } from "../../../orm/src/models/Job" ;
1+ import { log } from '@stacksjs/logging'
2+ import { Job } from "../../../orm/src/models/Job"
3+ import { runJob } from "./job"
4+
5+ interface QueuePayload {
6+ displayName : string ,
7+ name : string ,
8+ maxTries : number ,
9+ timeOut : number | null ,
10+ timeOutAt : Date | null
11+ }
212
313export async function processJobs ( ) : Promise < void > {
414 const jobs = await Job . all ( )
515
616 for ( const job of jobs ) {
7- console . log ( job )
17+ if ( job . payload ) {
18+ const payload : QueuePayload = JSON . parse ( job . payload )
19+ const currentAttempts = job . attempts || 0
20+ log . info ( `Running ${ payload . displayName } ` )
21+
22+ job . update ( { attempts : currentAttempts + 1 } )
23+
24+ try {
25+ await runJob ( payload . name , {
26+ queue : job . queue ,
27+ payload : { } ,
28+ context : '' ,
29+ maxTries : payload . maxTries ,
30+ timeout : 60 ,
31+ } )
32+ } catch ( error ) {
33+ log . info ( `${ payload . displayName } failed` )
34+ log . error ( error )
35+ }
36+
37+ log . info ( `Successfully ran ${ payload . displayName } ` )
38+ }
839 }
9- }
40+ }
Original file line number Diff line number Diff line change 11import type { JobOptions } from "./job"
2- import process from 'node:process'
32import Job from "../../../orm/src/models/Job"
43
54export async function storeJob ( name : string , options : JobOptions ) : Promise < void > {
65 const payloadJson = JSON . stringify ( {
76 displayName : `app/Jobs/${ name } .ts` ,
7+ name,
88 maxTries : options . tries || 1 ,
99 timeout : null ,
1010 timeoutAt : null
You can’t perform that action at this time.
0 commit comments