Skip to content

Commit d54d471

Browse files
committed
chore: wip
1 parent 9a0df1f commit d54d471

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

app/Jobs/ExampleJob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { log } from '@stacksjs/cli'
55
export default new Job({
66
name: 'Example Job', // optional, defaults to the file name
77
description: 'A demo cron job that runs every minute', // optional
8-
tries: 3, // optional, defaults to 3, in case of failures
8+
tries: 3, // optional, defaults to 3 retries, in case of failures
99
backoff: 3, // optional, defaults to 3-second delays between retries
1010
rate: Every.Minute, // optional, '* * * * *' in cron syntax (overwrites the Scheduler's definition)
1111
handle: () => { // action: 'SendWelcomeEmail', // instead of handle, you may target an action or `action: () => {`

storage/framework/core/cloud/src/cloud/queue.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ export class QueueStack {
3636
const jobModule = await this.loadJobModule(filePath)
3737

3838
// Now you can safely access jobModule.default.rate
39-
const rate = jobModule.default.rate || '* * * * *'
39+
const rate = jobModule.default?.rate
40+
41+
// if no rate or job is disabled, no need to schedule, skip
42+
if (!rate || jobModule.default?.enabled === false)
43+
continue
4044

41-
// Rest of your logic here...
4245
// Convert the rate to a Schedule object
4346
const schedule = Schedule.cron(this.cronScheduleFromRate(rate))
4447

4548
const id = `QueueRule${pascalCase(file.replace('.ts', ''))}`
49+
4650
// Perform operations with the jobModule.default as needed
4751
const rule = new Rule(this.scope, id, {
4852
// schedule to run every second
@@ -69,7 +73,7 @@ export class QueueStack {
6973
},
7074
],
7175

72-
retryAttempts: 3,
76+
retryAttempts: jobModule.default.tries || 3,
7377

7478
subnetSelection: {
7579
subnetType: ec2.SubnetType.PUBLIC, // SubnetType.PRIVATE_WITH_EGRESS

storage/framework/core/scheduler/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type {
1313
Ranges,
1414
TimeUnit,
1515
} from './types/cron'
16+
export * from './types/utils'
1617

1718
export * from './schedule'
1819

storage/framework/core/types/src/cron-jobs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { IntRange } from '@stacksjs/scheduler'
2+
13
/**
24
* Cron Job Options.
35
*/
@@ -12,7 +14,10 @@ export interface JobOptions {
1214
description?: string
1315
queue?: string
1416
timezone?: string
15-
tries?: number
17+
/**
18+
* Number of tries. Must be between 0 and 185.
19+
*/
20+
tries?: IntRange<0, 185>
1621
backoff?: number | number[]
1722
rate?: string | Every
1823
enabled?: boolean

0 commit comments

Comments
 (0)