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() {
65
65
cmd . make ( buddy )
66
66
cmd . migrate ( buddy )
67
67
cmd . outdated ( buddy )
68
+ cmd . queue ( buddy )
68
69
cmd . release ( buddy )
69
70
cmd . route ( buddy )
70
71
cmd . saas ( buddy )
Original file line number Diff line number Diff line change @@ -40,8 +40,6 @@ export interface JobOptions {
40
40
}
41
41
42
42
export async function runJob ( name : string , options : JobOptions = { } ) : Promise < void > {
43
- log . info ( `Running job: ${ name } ` )
44
-
45
43
try {
46
44
const jobModule = await import ( appPath ( `Jobs/${ name } .ts` ) )
47
45
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
+ }
2
12
3
13
export async function processJobs ( ) : Promise < void > {
4
14
const jobs = await Job . all ( )
5
15
6
16
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
+ }
8
39
}
9
- }
40
+ }
Original file line number Diff line number Diff line change 1
1
import type { JobOptions } from "./job"
2
- import process from 'node:process'
3
2
import Job from "../../../orm/src/models/Job"
4
3
5
4
export async function storeJob ( name : string , options : JobOptions ) : Promise < void > {
6
5
const payloadJson = JSON . stringify ( {
7
6
displayName : `app/Jobs/${ name } .ts` ,
7
+ name,
8
8
maxTries : options . tries || 1 ,
9
9
timeout : null ,
10
10
timeoutAt : null
You can’t perform that action at this time.
0 commit comments