@stacksjs/scheduler 0.67.0 → 0.68.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cron.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export type { CronCallback, CronCommand, CronContext, CronJobParams, CronOnCompleteCallback, CronOnCompleteCommand, Ranges, TimeUnit } from "cron";
2
- export { CronJob, CronTime } from "cron";
1
+ export type {;
2
+ export { CronJob, CronTime } from 'cron'
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./cron";
2
- export * from "./schedule";
3
- export * from "./types";
1
+ export * from './cron'
2
+ export * from './schedule'
3
+ export * from './types'
@@ -1,32 +1,131 @@
1
- import type { DateTime } from "luxon";
1
+ import type { DateTime } from 'luxon';
2
+
2
3
  export declare class Schedule {
3
- private cronPattern;
4
- private timezone;
5
- private readonly task;
6
- constructor(task: () => void);
7
- everySecond(): Schedule;
8
- everyMinute(): Schedule;
9
- everyTwoMinutes(): Schedule;
10
- everyFiveMinutes(): Schedule;
11
- everyTenMinutes(): Schedule;
12
- everyThirtyMinutes(): Schedule;
13
- everyHour(): Schedule;
14
- everyDay(): Schedule;
15
- hourly(): Schedule;
16
- daily(): Schedule;
17
- weekly(): Schedule;
18
- monthly(): Schedule;
19
- yearly(): Schedule;
20
- onDays(days: number[]): Schedule;
21
- at(time: string): Schedule;
22
- setTimeZone(timezone: string): Schedule;
23
- start(): void;
24
- job(path: string): Schedule;
25
- action(path: string): Schedule;
26
- static command(cmd: string): Schedule;
4
+ private cronPattern = ''
5
+ private timezone = 'America/Los_Angeles'
6
+ private readonly task: () => void
7
+
8
+ constructor(task: () => void) {
9
+ this.task = task
10
+ }
11
+
12
+ everySecond(): Schedule {
13
+ this.cronPattern = '* * * * * *'
14
+ return this
15
+ }
16
+
17
+ everyMinute(): Schedule {
18
+ this.cronPattern = '0 * * * * *'
19
+ return this
20
+ }
21
+
22
+ everyTwoMinutes(): Schedule {
23
+ this.cronPattern = '*/2 * * * * *'
24
+ return this
25
+ }
26
+
27
+ everyFiveMinutes(): Schedule {
28
+ this.cronPattern = '*/5 * * * *'
29
+ return this
30
+ }
31
+
32
+ everyTenMinutes(): Schedule {
33
+ this.cronPattern = '*/10 * * * *'
34
+ return this
35
+ }
36
+
37
+ everyThirtyMinutes(): Schedule {
38
+ this.cronPattern = '*/30 * * * *'
39
+ return this
40
+ }
41
+
42
+ everyHour(): Schedule {
43
+ this.cronPattern = '0 0 * * * *'
44
+ return this
45
+ }
46
+
47
+ everyDay(): Schedule {
48
+ this.cronPattern = '0 0 0 * * *'
49
+ return this
50
+ }
51
+
52
+ hourly(): Schedule {
53
+ this.cronPattern = '0 0 * * * *'
54
+ return this
55
+ }
56
+
57
+ daily(): Schedule {
58
+ this.cronPattern = '0 0 0 * * *'
59
+ return this
60
+ }
61
+
62
+ weekly(): Schedule {
63
+ this.cronPattern = '0 0 0 * * 0'
64
+ return this
65
+ }
66
+
67
+ monthly(): Schedule {
68
+ this.cronPattern = '0 0 0 1 * *'
69
+ return this
70
+ }
71
+
72
+ yearly(): Schedule {
73
+ this.cronPattern = '0 0 0 1 1 *'
74
+ return this
75
+ }
76
+
77
+ onDays(days: number[]): Schedule {
78
+ const dayPattern = days.join(',')
79
+ this.cronPattern = `0 0 0 * * ${dayPattern}`
80
+ return this
81
+ }
82
+
83
+
84
+ at(time: string): Schedule {
85
+ const [hour, minute] = time.split(':').map(Number)
86
+ this.cronPattern = `${minute} ${hour} * * *`
87
+ return this
88
+ }
89
+
90
+ setTimeZone(timezone: string): Schedule {
91
+ this.timezone = timezone
92
+ return this
93
+ }
94
+
95
+ start(): void {
96
+ new CronJob(this.cronPattern, this.task, null, true, this.timezone)
97
+ log.info(`Scheduled task with pattern: ${this.cronPattern} in timezone: ${this.timezone}`)
98
+ }
99
+
100
+ job(path: string): Schedule {
101
+ log.info(`Scheduling job: ${path}`)
102
+ return this
103
+ }
104
+
105
+ action(path: string): Schedule {
106
+ log.info(`Scheduling action: ${path}`)
107
+ return this
108
+ }
109
+
110
+ static command(cmd: string): Schedule {
111
+ log.info(`Executing command: ${cmd}`)
112
+ return new Schedule(async () => {
113
+ log.info(`Executing command: ${cmd}`)
114
+
115
+ const result = await runCommand(cmd)
116
+
117
+ if (result.isErr()) {
118
+ log.error(result.error)
119
+ return
120
+ }
121
+
122
+ log.info(result.value)
123
+ })
124
+ }
27
125
  }
28
126
  export declare class Job extends Schedule {}
29
127
  export declare function sendAt(cronTime: string | Date | DateTime): DateTime;
30
128
  export declare function timeout(cronTime: string | Date | DateTime): number;
31
- export type Scheduler = typeof Schedule;
32
- export default Schedule;
129
+ export declare type Scheduler = typeof Schedule
130
+
131
+ export default Schedule;
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export type IntRange<
2
- Min extends number,
3
- Max extends number
4
- > = number extends Min | Max ? never : number | [Min | number, Max | number];
1
+ export declare type IntRange<Min extends number, Max extends number> = number extends Min | Max
2
+ ? never
3
+ : number | [Min | number, Max | number]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/scheduler",
3
3
  "type": "module",
4
- "version": "0.67.0",
4
+ "version": "0.68.1",
5
5
  "description": "The Stacks scheduler.",
6
6
  "author": "Chris Breuer",
7
7
  "contributors": ["Chris Breuer <chris@stacksjs.org>"],