Skip to content

Commit 08037dc

Browse files
committed
chore: wip
chore: wip
1 parent abe8634 commit 08037dc

File tree

8 files changed

+44
-24
lines changed

8 files changed

+44
-24
lines changed

app/Jobs/DummyJob.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default new Job({
88
queue: 'default', // defaults to 'default'
99
tries: 3, // defaults to 3, in case of failures
1010
backoff: 3, // defaults to 3-second delays between retries
11-
schedule: Every.FiveSeconds, // '*/5 * * * *' in cron syntax (overwrites the Scheduler's definition)
11+
rate: Every.Minute, // '* * * * *' in cron syntax (overwrites the Scheduler's definition)
1212
handle: () => {
1313
log.info('This cron job log this message every 5 seconds')
1414
},

app/Schedule.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// import run from '@stacksjs/scheduler'
1+
import run from '@stacksjs/scheduler'
22

3-
// export default function () {
4-
// run.command('bun /home/some/script.js').everySecond()
5-
// run.command('bun /home/some/other/script.ts').everyMinute()
6-
// run.job('DummyJob.ts').everyTenMinutes() // scans ./app/Jobs/*
7-
// // schedule.action('SomeAction.ts').everyFiveMinutes() // you may also trigger an action - scans ./app/Actions/*
8-
// run.exec('bun /home/some/script.ts').everyMinute()
9-
// run.call(() => {
10-
// // eslint-disable-next-line no-console
11-
// console.log('a "fancy callback" that runs weekly (Mondays) at 1:00 PM PT')
12-
// }).weekly().mondays().at('13:00').timezone('America/Los_Angeles')
13-
// }
3+
export default function () {
4+
run.command('bun /home/some/script.js').everySecond()
5+
run.command('bun /home/some/other/script.ts').everyMinute()
6+
run.job('DummyJob.ts').everyTenMinutes() // scans ./app/Jobs/*
7+
// schedule.action('SomeAction.ts').everyFiveMinutes() // you may also trigger an action - scans ./app/Actions/*
8+
run.exec('bun /home/some/script.ts').everyMinute()
9+
run.call(() => {
10+
// eslint-disable-next-line no-console
11+
console.log('a "fancy callback" that runs weekly (Mondays) at 1:00 PM PT')
12+
}).weekly().mondays().at('13:00').timezone('America/Los_Angeles')
13+
}

bun.lockb

12.5 KB
Binary file not shown.

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { aws_ec2 as ec2 } from 'aws-cdk-lib'
1+
import type { Cluster, TaskDefinition } from 'aws-cdk-lib'
2+
import { CfnOutput as Output, Size, aws_batch as batch, aws_ec2 as ec2, aws_ecs as ecs } from 'aws-cdk-lib'
3+
import { path as p } from '@stacksjs/path'
4+
import type { Construct } from 'constructs'
25
import { Rule, Schedule } from 'aws-cdk-lib/aws-events'
36
import { EcsTask } from 'aws-cdk-lib/aws-events-targets'
4-
import type { Cluster, TaskDefinition } from 'aws-cdk-lib/aws-ecs'
5-
import type { Construct } from 'constructs'
67
import type { NestedCloudProps } from '../types'
78

89
export interface QueueStackProps extends NestedCloudProps {
@@ -12,11 +13,10 @@ export interface QueueStackProps extends NestedCloudProps {
1213

1314
export class QueueStack {
1415
constructor(scope: Construct, props: QueueStackProps) {
15-
const rule = new Rule(scope, 'Rule', {
16+
const rule = new Rule(scope, 'QueueRule', {
1617
// schedule to run every second
1718
ruleName: `${props.appName}-${props.appEnv}-queue`,
1819
schedule: Schedule.cron({ minute: '*', hour: '*', month: '*', weekDay: '*', year: '*' }),
19-
// schedule: Schedule.cron({ minute: '0', hour: '0' }), // For example, every day at midnight
2020
})
2121

2222
rule.addTarget(new EcsTask({
@@ -37,9 +37,11 @@ export class QueueStack {
3737
],
3838
},
3939
],
40+
4041
retryAttempts: 3,
42+
4143
subnetSelection: {
42-
subnetType: ec2.SubnetType.PUBLIC,
44+
subnetType: ec2.SubnetType.PUBLIC, // SubnetType.PRIVATE_WITH_EGRESS
4345
},
4446
}))
4547
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ export function eslintPath(path?: string) {
242242
return lintPath(`eslint/${path || ''}`)
243243
}
244244

245+
export function jobsPath(path?: string) {
246+
return resourcesPath(`jobs/${path || ''}`)
247+
}
248+
245249
export function loggingPath(path?: string) {
246250
return corePath(`logging/${path || ''}`)
247251
}
@@ -490,6 +494,7 @@ export const path = {
490494
libraryEntryPath,
491495
lintPath,
492496
loggingPath,
497+
jobsPath,
493498
modulesPath,
494499
ormPath,
495500
objectsPath,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface JobOptions {
1414
timezone?: string
1515
tries?: number
1616
backoff?: number | number[]
17-
schedule?: string | Every
17+
rate?: string | Every
1818
enabled?: boolean
1919
}
2020

@@ -30,10 +30,10 @@ export type CronJobs = Jobs
3030
// export type CronJobs = Jobs
3131

3232
export enum Every {
33-
Second = '* * * * * *',
34-
FiveSeconds = '*/5 * * * * *',
35-
TenSeconds = '*/10 * * * * *',
36-
ThirtySeconds = '*/30 * * * * *',
33+
// Second = '* * * * * *',
34+
// FiveSeconds = '*/5 * * * * *',
35+
// TenSeconds = '*/10 * * * * *',
36+
// ThirtySeconds = '*/30 * * * * *',
3737
Minute = '* * * * *',
3838
Hour = '0 * * * *',
3939
HalfHour = '0,30 * * * *',

storage/framework/ide/dictionary.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ entrypoints
9595
envrc
9696
eventstream
9797
execa
98+
fairshare
9899
Fargate
99100
filesize
100101
flareapp
@@ -166,6 +167,7 @@ marvinpinto
166167
mattpocock
167168
mdit
168169
mdsvex
170+
mebibytes
169171
meema
170172
meemalabs
171173
meilisearch

storage/framework/server/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
import process from 'node:process'
12
import type { Server, ServerWebSocket } from 'bun'
23
import { serverResponse } from '@stacksjs/router'
4+
import { path as p } from '@stacksjs/path'
5+
6+
if (process.env.QUEUE_WORKER) {
7+
if (!process.env.JOB)
8+
throw new Error('Missing JOB environment variable')
9+
10+
const jobModule = await import(p.jobsPath('DummyJob'))
11+
await jobModule.default.handle()
12+
process.exit(0)
13+
}
314

415
const server = Bun.serve({
516
port: 3000,

0 commit comments

Comments
 (0)