Skip to content

Commit 5f170f7

Browse files
committed
chore: wip
1 parent 6591fe5 commit 5f170f7

File tree

7 files changed

+88
-41
lines changed

7 files changed

+88
-41
lines changed

.stacks/core/types/src/cron-jobs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export interface JobOptions {
88
name?: string
99
// eslint-disable-next-line @typescript-eslint/ban-types
1010
run: string | Function
11-
schedule?: string
1211
description?: string
1312
timezone?: string
1413
tries?: number

.stacks/core/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from './push'
3636
export * from './queue'
3737
export * from './reactivity'
3838
export * from './router'
39+
export * from './scheduler'
3940
export * from './search-engine'
4041
export * from './security'
4142
export * from './services'

.stacks/core/types/src/scheduler.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export interface Scheduler {
2+
schedule(schedule: Schedule): void
3+
}
4+
5+
export interface Schedule {
6+
action(action: string): this
7+
command(cmd: string): this
8+
job(job: string): this
9+
exec(cmd: string): this
10+
call(callback: () => void): this
11+
everyMinute(): this
12+
everySecond(): this
13+
everyFiveMinutes(): this
14+
everyTenMinutes(): this
15+
everyThirtyMinutes(): this
16+
hourly(): this
17+
daily(): this
18+
twiceDaily(hour1: number, hour2: number): this
19+
weekly(): this
20+
monthly(): this
21+
quarterly(): this
22+
yearly(): this
23+
weekdays(): this
24+
weekends(): this
25+
mondays(): this
26+
tuesdays(): this
27+
wednesdays(): this
28+
thursdays(): this
29+
fridays(): this
30+
saturdays(): this
31+
sundays(): this
32+
between(startTime: string, endTime: string): this
33+
timezone(timezone: string): this
34+
when(callback: () => boolean): this
35+
at(time: string): this
36+
}

app/jobs/demo-job.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { log } from '@stacksjs/logging'
2-
import { Every } from '@stacksjs/types'
32
import { Job } from '@stacksjs/queue'
43

54
export default new Job({
65
name: 'Demo Job', // defaults to the file name
76
description: 'A demo cron job that runs every 5th minute', // optional
8-
schedule: Every.FifthMinute, // optional, run it on a schedule. alternatively, '*/5 * * * *'
97
// `run: 'demo-job'` is another option where `demo-job` refers to ./resources/functions/demo-job.ts
108
tries: 3, // defaults to 3, in case of failures
119
backoff: 3, // defaults to 3-second delays between retries

app/schedule.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Schedule, Scheduler } from '../.stacks/core/types/src/scheduler'
2+
3+
export default <Scheduler> {
4+
schedule(schedule: Schedule) {
5+
schedule.command('bun /home/some/script.js').everySecond()
6+
schedule.command('bun /home/some/other/script.ts').everyMinute()
7+
schedule.action('path/to/action').everyFiveMinutes()
8+
schedule.job('path/to/job').everyTenMinutes()
9+
schedule.exec('bun /home/some/script.js').everyMinute()
10+
schedule.call(() => {
11+
// ...
12+
}).weekly().mondays().at('13:00').timezone('America/Los_Angeles')
13+
},
14+
}

bun.lockb

-1 Bytes
Binary file not shown.

config/security.ts

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { defineSecurity } from '../.stacks/core/config/src/helpers'
77
* hover any of the options below and the definitions will be provided. In case you
88
* have any questions, feel free to reach out via Discord or GitHub Discussions.
99
*/
10-
1110
export default defineSecurity({
1211
appFirewall: {
1312
immunity: 300, // CAPTCHA immunity time 300 seconds
@@ -20,7 +19,7 @@ export default defineSecurity({
2019
},
2120

2221
rules: [
23-
// rule to limit requests to 100 per 5 minutes
22+
// rule to limit requests to 1000 per 5 minutes
2423
{
2524
action: { block: {} },
2625
name: 'RateLimitRule',
@@ -41,7 +40,7 @@ export default defineSecurity({
4140
// use managed rule AWSManagedRulesAmazonIpReputationList
4241
{
4342
name: 'AWSManagedRulesAmazonIpReputationList',
44-
priority: 2,
43+
priority: 1,
4544
// use rule action
4645
action: { allow: {} },
4746
visibilityConfig: {
@@ -60,7 +59,7 @@ export default defineSecurity({
6059
// use managed rule AWSManagedRulesKnownBadInputsRuleSet
6160
{
6261
name: 'AWSManagedRulesKnownBadInputsRuleSet',
63-
priority: 3,
62+
priority: 2,
6463
// use rule action
6564
action: { allow: {} },
6665
visibilityConfig: {
@@ -77,42 +76,42 @@ export default defineSecurity({
7776
},
7877

7978
// use managed rule Account takeover prevention
80-
{
81-
name: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
82-
priority: 4,
83-
// use rule action
84-
action: { allow: {} },
85-
visibilityConfig: {
86-
sampledRequestsEnabled: true,
87-
cloudWatchMetricsEnabled: true,
88-
metricName: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
89-
},
90-
statement: {
91-
managedRuleGroupStatement: {
92-
vendorName: 'AWS',
93-
name: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
94-
},
95-
},
96-
},
79+
// {
80+
// name: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
81+
// priority: 4,
82+
// // use rule action
83+
// action: { allow: {} },
84+
// visibilityConfig: {
85+
// sampledRequestsEnabled: true,
86+
// cloudWatchMetricsEnabled: true,
87+
// metricName: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
88+
// },
89+
// statement: {
90+
// managedRuleGroupStatement: {
91+
// vendorName: 'AWS',
92+
// name: 'AWSManagedRulesAccountTakeoverProtectionRuleSet',
93+
// },
94+
// },
95+
// },
9796

9897
// use managed rule Account creation fraud prevention
99-
{
100-
name: 'AWSManagedRulesAdminProtectionRuleSet',
101-
priority: 5,
102-
// use rule action
103-
action: { allow: {} },
104-
visibilityConfig: {
105-
sampledRequestsEnabled: true,
106-
cloudWatchMetricsEnabled: true,
107-
metricName: 'AWSManagedRulesAdminProtectionRuleSet',
108-
},
109-
statement: {
110-
managedRuleGroupStatement: {
111-
vendorName: 'AWS',
112-
name: 'AWSManagedRulesAdminProtectionRuleSet',
113-
},
114-
},
115-
},
98+
// {
99+
// name: 'AWSManagedRulesAdminProtectionRuleSet',
100+
// priority: 5,
101+
// // use rule action
102+
// action: { allow: {} },
103+
// visibilityConfig: {
104+
// sampledRequestsEnabled: true,
105+
// cloudWatchMetricsEnabled: true,
106+
// metricName: 'AWSManagedRulesAdminProtectionRuleSet',
107+
// },
108+
// statement: {
109+
// managedRuleGroupStatement: {
110+
// vendorName: 'AWS',
111+
// name: 'AWSManagedRulesAdminProtectionRuleSet',
112+
// },
113+
// },
114+
// },
116115
],
117116
},
118117
})

0 commit comments

Comments
 (0)