@dbos-inc/dbos-sdk 1.8.23-preview.g8060c74f33 → 1.9.5-preview

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. package/dist/schemas/system_db_schema.d.ts +4 -0
  2. package/dist/schemas/system_db_schema.d.ts.map +1 -1
  3. package/dist/src/dbos-executor.d.ts.map +1 -1
  4. package/dist/src/dbos-executor.js +10 -2
  5. package/dist/src/dbos-executor.js.map +1 -1
  6. package/dist/src/dbos-runtime/cli.d.ts +1 -0
  7. package/dist/src/dbos-runtime/cli.d.ts.map +1 -1
  8. package/dist/src/dbos-runtime/cli.js +4 -2
  9. package/dist/src/dbos-runtime/cli.js.map +1 -1
  10. package/dist/src/dbos-runtime/config.d.ts.map +1 -1
  11. package/dist/src/dbos-runtime/config.js +6 -0
  12. package/dist/src/dbos-runtime/config.js.map +1 -1
  13. package/dist/src/dbos-runtime/runtime.d.ts +1 -0
  14. package/dist/src/dbos-runtime/runtime.d.ts.map +1 -1
  15. package/dist/src/dbos-runtime/runtime.js +7 -0
  16. package/dist/src/dbos-runtime/runtime.js.map +1 -1
  17. package/dist/src/index.d.ts +1 -0
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/index.js +5 -1
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/kafka/kafka.d.ts +1 -0
  22. package/dist/src/kafka/kafka.d.ts.map +1 -1
  23. package/dist/src/kafka/kafka.js +35 -1
  24. package/dist/src/kafka/kafka.js.map +1 -1
  25. package/dist/src/scheduler/crontab.d.ts +19 -0
  26. package/dist/src/scheduler/crontab.d.ts.map +1 -0
  27. package/dist/src/scheduler/crontab.js +286 -0
  28. package/dist/src/scheduler/crontab.js.map +1 -0
  29. package/dist/src/scheduler/scheduler.d.ts +45 -0
  30. package/dist/src/scheduler/scheduler.d.ts.map +1 -0
  31. package/dist/src/scheduler/scheduler.js +165 -0
  32. package/dist/src/scheduler/scheduler.js.map +1 -0
  33. package/dist/src/system_database.d.ts +4 -0
  34. package/dist/src/system_database.d.ts.map +1 -1
  35. package/dist/src/system_database.js +22 -0
  36. package/dist/src/system_database.js.map +1 -1
  37. package/dist/src/testing/testing_runtime.d.ts.map +1 -1
  38. package/dist/src/testing/testing_runtime.js +5 -0
  39. package/dist/src/testing/testing_runtime.js.map +1 -1
  40. package/dist/src/workflow.d.ts.map +1 -1
  41. package/dist/src/workflow.js.map +1 -1
  42. package/dist/tsconfig.build.tsbuildinfo +1 -1
  43. package/migrations/20240430090000_tables.js +13 -0
  44. package/package.json +1 -1
@@ -0,0 +1,286 @@
1
+ "use strict";
2
+ // This code was based on code from node-cron:
3
+ // https://github.com/node-cron/node-cron
4
+ /*
5
+ ISC License
6
+ Copyright (c) 2016, Lucas Merencia <lucas.merencia@gmail.com>
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted, provided that the above
10
+ copyright notice and this permission notice appear in all copies.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.TimeMatcher = exports.convertExpression = exports.validateCrontab = exports.convertAsterisksToRanges = void 0;
22
+ function removeExtraSpaces(str) {
23
+ return str.replace(/\s{2,}/g, ' ').trim();
24
+ }
25
+ function prependSecondExpression(expressions) {
26
+ if (expressions.length === 5) {
27
+ return ['0'].concat(expressions);
28
+ }
29
+ return expressions;
30
+ }
31
+ const months = ['january', 'february', 'march', 'april', 'may', 'june', 'july',
32
+ 'august', 'september', 'october', 'november', 'december'];
33
+ const shortMonths = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug',
34
+ 'sep', 'oct', 'nov', 'dec'];
35
+ function convertMonthNameI(expression, items) {
36
+ for (let i = 0; i < items.length; i++) {
37
+ expression = expression.replace(new RegExp(items[i], 'gi'), `${i + 1}`);
38
+ }
39
+ return expression;
40
+ }
41
+ function monthNamesConversion(monthExpression) {
42
+ monthExpression = convertMonthNameI(monthExpression, months);
43
+ monthExpression = convertMonthNameI(monthExpression, shortMonths);
44
+ return monthExpression;
45
+ }
46
+ const weekDays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday',
47
+ 'friday', 'saturday'];
48
+ const shortWeekDays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
49
+ function convertWeekDayName(weekExpression, items) {
50
+ for (let i = 0; i < items.length; i++) {
51
+ weekExpression = weekExpression.replace(new RegExp(items[i], 'gi'), `${i}`);
52
+ }
53
+ return weekExpression;
54
+ }
55
+ function weekDayNamesConversion(expression) {
56
+ expression = expression.replace('7', '0');
57
+ expression = convertWeekDayName(expression, weekDays);
58
+ return convertWeekDayName(expression, shortWeekDays);
59
+ }
60
+ function convertAsterisk(expression, replacement) {
61
+ if (expression.indexOf('*') !== -1) {
62
+ return expression.replace('*', replacement);
63
+ }
64
+ return expression;
65
+ }
66
+ // Based on position in full crontab, convert asterisk to appropriate range
67
+ function convertAsterisksToRanges(expressions) {
68
+ expressions[0] = convertAsterisk(expressions[0], '0-59');
69
+ expressions[1] = convertAsterisk(expressions[1], '0-59');
70
+ expressions[2] = convertAsterisk(expressions[2], '0-23');
71
+ expressions[3] = convertAsterisk(expressions[3], '1-31');
72
+ expressions[4] = convertAsterisk(expressions[4], '1-12');
73
+ expressions[5] = convertAsterisk(expressions[5], '0-6');
74
+ return expressions;
75
+ }
76
+ exports.convertAsterisksToRanges = convertAsterisksToRanges;
77
+ function replaceWithRange(expression, text, init, end) {
78
+ const numbers = [];
79
+ let last = parseInt(end);
80
+ let first = parseInt(init);
81
+ if (first > last) {
82
+ last = parseInt(init);
83
+ first = parseInt(end);
84
+ }
85
+ for (let i = first; i <= last; i++) {
86
+ numbers.push(i.toString());
87
+ }
88
+ return expression.replace(new RegExp(text, 'i'), numbers.join());
89
+ }
90
+ function convertRange(expression) {
91
+ const rangeRegEx = /(\d+)-(\d+)/;
92
+ let match = rangeRegEx.exec(expression);
93
+ while (match !== null && match.length > 0) {
94
+ expression = replaceWithRange(expression, match[0], match[1], match[2]);
95
+ match = rangeRegEx.exec(expression);
96
+ }
97
+ return expression;
98
+ }
99
+ function convertAllRanges(expressions) {
100
+ for (let i = 0; i < expressions.length; i++) {
101
+ expressions[i] = convertRange(expressions[i]);
102
+ }
103
+ return expressions;
104
+ }
105
+ function convertSteps(expressions) {
106
+ const stepValuePattern = /^(.+)\/(\w+)$/;
107
+ for (let i = 0; i < expressions.length; i++) {
108
+ const match = stepValuePattern.exec(expressions[i]);
109
+ const isStepValue = match !== null && match.length > 0;
110
+ if (isStepValue) {
111
+ const baseDivider = match[2];
112
+ if (isNaN(parseInt(baseDivider))) {
113
+ throw new Error(baseDivider + ' is not a valid step value');
114
+ }
115
+ const values = match[1].split(',');
116
+ const stepValues = [];
117
+ const divider = parseInt(baseDivider, 10);
118
+ for (let j = 0; j <= values.length; j++) {
119
+ const value = parseInt(values[j], 10);
120
+ if (value % divider === 0) {
121
+ stepValues.push(`${value}`);
122
+ }
123
+ }
124
+ expressions[i] = stepValues.join(',');
125
+ }
126
+ }
127
+ return expressions;
128
+ }
129
+ // Function that takes care of normalization.
130
+ function normalizeIntegers(expressions) {
131
+ for (let i = 0; i < expressions.length; i++) {
132
+ const numbers = expressions[i].split(',');
133
+ for (let j = 0; j < numbers.length; j++) {
134
+ numbers[j] = parseInt(numbers[j]).toString();
135
+ }
136
+ expressions[i] = numbers.join(',');
137
+ }
138
+ return expressions;
139
+ }
140
+ const validationRegex = /^(?:\d+|\*|\*\/\d+)$/;
141
+ // Check comma-delimited list to see if elements are in range
142
+ function isValidExpression(expression, min, max) {
143
+ const options = expression.split(',');
144
+ for (const option of options) {
145
+ const optionAsInt = parseInt(option, 10);
146
+ if ((!Number.isNaN(optionAsInt) &&
147
+ (optionAsInt < min || optionAsInt > max)) ||
148
+ !validationRegex.test(option)) {
149
+ return false;
150
+ }
151
+ }
152
+ return true;
153
+ }
154
+ function isInvalidSecond(expression) { return !isValidExpression(expression, 0, 59); }
155
+ function isInvalidMinute(expression) { return !isValidExpression(expression, 0, 59); }
156
+ function isInvalidHour(expression) { return !isValidExpression(expression, 0, 23); }
157
+ function isInvalidDayOfMonth(expression) { return !isValidExpression(expression, 1, 31); }
158
+ function isInvalidMonth(expression) { return !isValidExpression(expression, 1, 12); }
159
+ function isInvalidWeekDay(expression) { return !isValidExpression(expression, 0, 7); }
160
+ function validateFields(patterns, executablePatterns) {
161
+ if (isInvalidSecond(executablePatterns[0]))
162
+ throw new Error(`${patterns[0]} is a invalid expression for second`);
163
+ if (isInvalidMinute(executablePatterns[1]))
164
+ throw new Error(`${patterns[1]} is a invalid expression for minute`);
165
+ if (isInvalidHour(executablePatterns[2]))
166
+ throw new Error(`${patterns[2]} is a invalid expression for hour`);
167
+ if (isInvalidDayOfMonth(executablePatterns[3]))
168
+ throw new Error(`${patterns[3]} is a invalid expression for day of month`);
169
+ if (isInvalidMonth(executablePatterns[4]))
170
+ throw new Error(`${patterns[4]} is a invalid expression for month`);
171
+ if (isInvalidWeekDay(executablePatterns[5]))
172
+ throw new Error(`${patterns[5]} is a invalid expression for week day`);
173
+ }
174
+ /**
175
+ * Validates a Cron-Job expression pattern.
176
+ * Throws on error.
177
+ */
178
+ function validateCrontab(pattern) {
179
+ if (typeof pattern !== 'string')
180
+ throw new TypeError('pattern must be a string!');
181
+ const patterns = pattern.split(' ');
182
+ const executablePatterns = convertExpression(pattern).split(' ');
183
+ if (patterns.length === 5)
184
+ patterns.unshift('0');
185
+ validateFields(patterns, executablePatterns);
186
+ return executablePatterns.join(' ');
187
+ }
188
+ exports.validateCrontab = validateCrontab;
189
+ /*
190
+ * The node-cron core allows only numbers (including multiple numbers e.g 1,2).
191
+ * This module is going to translate the month names, week day names and ranges
192
+ * to integers relatives.
193
+ *
194
+ * Month names example:
195
+ * - expression 0 1 1 January,Sep *
196
+ * - Will be translated to 0 1 1 1,9 *
197
+ *
198
+ * Week day names example:
199
+ * - expression 0 1 1 2 Monday,Sat
200
+ * - Will be translated to 0 1 1 1,5 *
201
+ *
202
+ * Ranges example:
203
+ * - expression 1-5 * * * *
204
+ * - Will be translated to 1,2,3,4,5 * * * *
205
+ */
206
+ function convertExpression(crontab) {
207
+ let expressions = removeExtraSpaces(crontab).split(' ');
208
+ expressions = prependSecondExpression(expressions);
209
+ expressions[4] = monthNamesConversion(expressions[4]);
210
+ expressions[5] = weekDayNamesConversion(expressions[5]);
211
+ expressions = convertAsterisksToRanges(expressions);
212
+ expressions = convertAllRanges(expressions);
213
+ expressions = convertSteps(expressions);
214
+ expressions = normalizeIntegers(expressions);
215
+ return expressions.join(' ');
216
+ }
217
+ exports.convertExpression = convertExpression;
218
+ //////////
219
+ /// Time matcher
220
+ //////////
221
+ function matchPattern(pattern, nvalue) {
222
+ const value = `${nvalue}`;
223
+ if (pattern.indexOf(',') !== -1) {
224
+ const patterns = pattern.split(',');
225
+ return patterns.includes(value);
226
+ }
227
+ return pattern === value;
228
+ }
229
+ class TimeMatcher {
230
+ pattern;
231
+ expressions;
232
+ dtf;
233
+ timezone;
234
+ constructor(pattern, timezone) {
235
+ validateCrontab(pattern);
236
+ this.pattern = convertExpression(pattern);
237
+ this.timezone = timezone;
238
+ this.expressions = this.pattern.split(' ');
239
+ this.dtf = this.timezone
240
+ ? new Intl.DateTimeFormat('en-US', {
241
+ year: 'numeric',
242
+ month: '2-digit',
243
+ day: '2-digit',
244
+ hour: '2-digit',
245
+ minute: '2-digit',
246
+ second: '2-digit',
247
+ hourCycle: 'h23',
248
+ fractionalSecondDigits: 3,
249
+ timeZone: this.timezone
250
+ }) : null;
251
+ }
252
+ match(date) {
253
+ date = this.apply(date);
254
+ const runOnSecond = matchPattern(this.expressions[0], date.getSeconds());
255
+ const runOnMinute = matchPattern(this.expressions[1], date.getMinutes());
256
+ const runOnHour = matchPattern(this.expressions[2], date.getHours());
257
+ const runOnDay = this.runsThisDay(date);
258
+ return runOnSecond && runOnMinute && runOnHour && runOnDay;
259
+ }
260
+ runsThisDay(date) {
261
+ const runOnDay = matchPattern(this.expressions[3], date.getDate());
262
+ const runOnMonth = matchPattern(this.expressions[4], date.getMonth() + 1);
263
+ const runOnWeekDay = matchPattern(this.expressions[5], date.getDay());
264
+ return runOnDay && runOnMonth && runOnWeekDay;
265
+ }
266
+ nextWakeupTime(date) {
267
+ // This is conservative. Some schedules never occur, such as the 30th of February, but you can ask for them
268
+ let msec = Math.round(date.getTime());
269
+ // This can be optimized by skipping ahead, but unit test first
270
+ for (let maxIters = 3600; --maxIters; maxIters > 0) {
271
+ msec += 1000;
272
+ const nd = new Date(msec);
273
+ if (this.match(nd))
274
+ return nd;
275
+ }
276
+ return new Date(msec);
277
+ }
278
+ apply(date) {
279
+ if (this.dtf) {
280
+ return new Date(this.dtf.format(date));
281
+ }
282
+ return date;
283
+ }
284
+ }
285
+ exports.TimeMatcher = TimeMatcher;
286
+ //# sourceMappingURL=crontab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crontab.js","sourceRoot":"","sources":["../../../src/scheduler/crontab.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,2CAA2C;AAC3C;;;;;;;;;;;;;;;EAeE;;;AAEF,SAAS,iBAAiB,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;AAC9C,CAAC;AAED,SAAS,uBAAuB,CAAC,WAAqB;IAElD,I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
+ export declare enum SchedulerMode {
5
+ ExactlyOncePerInterval = "ExactlyOncePerInterval",
6
+ ExactlyOncePerIntervalWhenActive = "ExactlyOncePerIntervalWhenActive"
7
+ }
8
+ export declare class SchedulerConfig {
9
+ crontab: string;
10
+ mode?: SchedulerMode;
11
+ }
12
+ export type ScheduledArgs = [Date, Date];
13
+ export interface SchedulerRegistrationConfig {
14
+ schedulerConfig?: SchedulerConfig;
15
+ }
16
+ export declare class SchedulerRegistration<This, Args extends unknown[], Return> extends MethodRegistration<This, Args, Return> implements SchedulerRegistrationConfig {
17
+ schedulerConfig?: SchedulerConfig;
18
+ constructor(origFunc: (this: This, ...args: Args) => Promise<Return>);
19
+ }
20
+ export declare function Scheduled(schedulerConfig: SchedulerConfig): <This, Ctx extends WorkflowContext, Return>(target: object, propertyKey: string, inDescriptor: TypedPropertyDescriptor<(this: This, ctx: Ctx, args_0: Date, args_1: Date) => Promise<Return>>) => TypedPropertyDescriptor<(this: This, ctx: Ctx, args_1: Date, args_2: Date) => Promise<Return>>;
21
+ export declare class DBOSScheduler {
22
+ readonly dbosExec: DBOSExecutor;
23
+ constructor(dbosExec: DBOSExecutor);
24
+ schedLoops: DetachableLoop[];
25
+ schedTasks: Promise<void>[];
26
+ initScheduler(): void;
27
+ destroyScheduler(): Promise<void>;
28
+ logRegisteredSchedulerEndpoints(): void;
29
+ }
30
+ declare class DetachableLoop {
31
+ readonly dbosExec: DBOSExecutor;
32
+ readonly crontab: string;
33
+ readonly schedMode: SchedulerMode;
34
+ readonly scheduledMethod: SchedulerRegistration<unknown, unknown[], unknown>;
35
+ private isRunning;
36
+ private interruptResolve?;
37
+ private lastExec;
38
+ private timeMatcher;
39
+ constructor(dbosExec: DBOSExecutor, crontab: string, schedMode: SchedulerMode, scheduledMethod: SchedulerRegistration<unknown, unknown[], unknown>);
40
+ startLoop(): Promise<void>;
41
+ setStopLoopFlag(): void;
42
+ private sleepms;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=scheduler.d.ts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AAO,EAAE,MAAM;IAAE,QAAQ,CAAC,SAAS,EAAC,aAAa;IAC3F,QAAQ,CAAC,eAAe,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC;IANxF,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,gBAAgB,CAAC,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,WAAW,CAAc;gBAEZ,QAAQ,EAAE,YAAY,EAAW,OAAO,EAAE,MAAM,EAAW,SAAS,EAAC,aAAa,EAClF,eAAe,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC;IAOlF,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IA8DhC,eAAe;IAQf,OAAO,CAAC,OAAO;CAGlB"}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DBOSScheduler = exports.Scheduled = exports.SchedulerRegistration = exports.SchedulerConfig = exports.SchedulerMode = void 0;
4
+ const decorators_1 = require("../decorators");
5
+ const crontab_1 = require("./crontab");
6
+ ////
7
+ // Configuration
8
+ ////
9
+ var SchedulerMode;
10
+ (function (SchedulerMode) {
11
+ SchedulerMode["ExactlyOncePerInterval"] = "ExactlyOncePerInterval";
12
+ SchedulerMode["ExactlyOncePerIntervalWhenActive"] = "ExactlyOncePerIntervalWhenActive";
13
+ })(SchedulerMode || (exports.SchedulerMode = SchedulerMode = {}));
14
+ class SchedulerConfig {
15
+ crontab = '* * * * *'; // Every minute
16
+ mode = SchedulerMode.ExactlyOncePerInterval;
17
+ }
18
+ exports.SchedulerConfig = SchedulerConfig;
19
+ class SchedulerRegistration extends decorators_1.MethodRegistration {
20
+ schedulerConfig;
21
+ constructor(origFunc) {
22
+ super(origFunc);
23
+ }
24
+ }
25
+ exports.SchedulerRegistration = SchedulerRegistration;
26
+ function Scheduled(schedulerConfig) {
27
+ function scheddec(target, propertyKey, inDescriptor) {
28
+ const { descriptor, registration } = (0, decorators_1.registerAndWrapFunction)(target, propertyKey, inDescriptor);
29
+ const schedRegistration = registration;
30
+ schedRegistration.schedulerConfig = schedulerConfig;
31
+ return descriptor;
32
+ }
33
+ return scheddec;
34
+ }
35
+ exports.Scheduled = Scheduled;
36
+ ///////////////////////////
37
+ // Scheduler Management
38
+ ///////////////////////////
39
+ class DBOSScheduler {
40
+ dbosExec;
41
+ constructor(dbosExec) {
42
+ this.dbosExec = dbosExec;
43
+ }
44
+ schedLoops = [];
45
+ schedTasks = [];
46
+ initScheduler() {
47
+ for (const registeredOperation of this.dbosExec.registeredOperations) {
48
+ const ro = registeredOperation;
49
+ if (ro.schedulerConfig) {
50
+ const loop = new DetachableLoop(this.dbosExec, ro.schedulerConfig.crontab ?? '* * * * *', ro.schedulerConfig.mode ?? SchedulerMode.ExactlyOncePerInterval, ro);
51
+ this.schedLoops.push(loop);
52
+ this.schedTasks.push(loop.startLoop());
53
+ }
54
+ }
55
+ }
56
+ async destroyScheduler() {
57
+ for (const l of this.schedLoops) {
58
+ l.setStopLoopFlag();
59
+ }
60
+ this.schedLoops = [];
61
+ try {
62
+ await Promise.allSettled(this.schedTasks);
63
+ }
64
+ catch (e) {
65
+ // What gets caught here is the loop stopping, which is what we wanted.
66
+ }
67
+ this.schedTasks = [];
68
+ }
69
+ logRegisteredSchedulerEndpoints() {
70
+ const logger = this.dbosExec.logger;
71
+ logger.info("Scheduled endpoints:");
72
+ this.dbosExec.registeredOperations.forEach((registeredOperation) => {
73
+ const ro = registeredOperation;
74
+ if (ro.schedulerConfig) {
75
+ logger.info(` ${ro.name} @ ${ro.schedulerConfig.crontab}; ${ro.schedulerConfig.mode ?? SchedulerMode.ExactlyOncePerInterval}`);
76
+ }
77
+ });
78
+ }
79
+ }
80
+ exports.DBOSScheduler = DBOSScheduler;
81
+ class DetachableLoop {
82
+ dbosExec;
83
+ crontab;
84
+ schedMode;
85
+ scheduledMethod;
86
+ isRunning = false;
87
+ interruptResolve;
88
+ lastExec;
89
+ timeMatcher;
90
+ constructor(dbosExec, crontab, schedMode, scheduledMethod) {
91
+ this.dbosExec = dbosExec;
92
+ this.crontab = crontab;
93
+ this.schedMode = schedMode;
94
+ this.scheduledMethod = scheduledMethod;
95
+ this.lastExec = new Date();
96
+ this.lastExec.setMilliseconds(0);
97
+ this.timeMatcher = new crontab_1.TimeMatcher(crontab);
98
+ }
99
+ async startLoop() {
100
+ // See if the exec time is available in durable storage...
101
+ if (this.schedMode !== SchedulerMode.ExactlyOncePerInterval) {
102
+ const lasttm = await this.dbosExec.systemDatabase.getLastScheduledTime(this.scheduledMethod.name);
103
+ if (lasttm) {
104
+ this.lastExec = new Date(lasttm);
105
+ }
106
+ }
107
+ this.isRunning = true;
108
+ while (this.isRunning) {
109
+ const nextExecTime = this.timeMatcher.nextWakeupTime(this.lastExec);
110
+ const sleepTime = nextExecTime.getTime() - new Date().getTime();
111
+ if (sleepTime > 0) {
112
+ // Wait for either the timeout or an interruption
113
+ await Promise.race([
114
+ this.sleepms(sleepTime),
115
+ new Promise((_, reject) => this.interruptResolve = reject)
116
+ ])
117
+ .catch(); // Interrupt sleep throws
118
+ }
119
+ if (!this.isRunning) {
120
+ break;
121
+ }
122
+ // Check crontab
123
+ // If this "wake up" time is not on the schedule, we shouldn't execute.
124
+ // (While ATOW this wake-up time is a scheduled run time, it is not
125
+ // contractually obligated to be so. If this is obligated to be a
126
+ // scheduled execution time, then we could make this an assertion
127
+ // instead of a check.)
128
+ if (!this.timeMatcher.match(nextExecTime)) {
129
+ this.lastExec = nextExecTime;
130
+ continue;
131
+ }
132
+ // Init workflow
133
+ const workflowUUID = `sched-${this.scheduledMethod.name}-${nextExecTime.toISOString()}`;
134
+ this.dbosExec.logger.debug(`Executing scheduled workflow ${workflowUUID}`);
135
+ const wfParams = { workflowUUID: workflowUUID };
136
+ // All operations annotated with Scheduled decorators must take in these four
137
+ const args = [nextExecTime, new Date()];
138
+ // We currently only support scheduled workflows
139
+ if (this.scheduledMethod.workflowConfig) {
140
+ // Execute the workflow
141
+ await this.dbosExec.workflow(this.scheduledMethod.registeredFunction, wfParams, ...args);
142
+ }
143
+ else {
144
+ this.dbosExec.logger.error(`Function ${this.scheduledMethod.name} is @scheduled but not a workflow`);
145
+ }
146
+ // Record the time of the wf kicked off
147
+ const dbTime = await this.dbosExec.systemDatabase.setLastScheduledTime(this.scheduledMethod.name, nextExecTime.getTime());
148
+ if (dbTime && dbTime > nextExecTime.getTime())
149
+ nextExecTime.setTime(dbTime);
150
+ this.lastExec = nextExecTime;
151
+ }
152
+ }
153
+ setStopLoopFlag() {
154
+ if (!this.isRunning)
155
+ return;
156
+ this.isRunning = false;
157
+ if (this.interruptResolve) {
158
+ this.interruptResolve(); // Trigger the interruption
159
+ }
160
+ }
161
+ sleepms(ms) {
162
+ return new Promise(resolve => setTimeout(resolve, ms));
163
+ }
164
+ }
165
+ //# sourceMappingURL=scheduler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/scheduler/scheduler.ts"],"names":[],"mappings":";;;AAEA,8CAA4E;AAC5E,uCAAwC;AAGxC,IAAI;AACJ,gBAAgB;AAChB,IAAI;AAEJ,IAAY,aAGX;AAHD,WAAY,aAAa;IACrB,kEAAiD,CAAA;IACjD,sFAAqE,CAAA;AACzE,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB;AAED,MAAa,eAAe;IACxB,OAAO,GAAW,WAAW,CAAC,CAAC,eAAe;IAC9C,IAAI,GAAoB,aAAa,CAAC,sBAAsB,CAAC;CAChE;AAHD,0CAGC;AAaD,MAAa,qBAA4D,SAAQ,+BAAsC;IAGnH,eAAe,CAAmB;IAClC,YAAY,QAAwD;QAChE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpB,CAAC;CACJ;AAPD,sDAOC;AAED,SAAgB,SAAS,CAAC,eAAgC;IACtD,SAAS,QAAQ,CACb,MAAc,EACd,WAAmB,EACnB,YAAw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AC,CAAC,2BAA2B;QACxD,CAAC;IACL,CAAC;IAEO,OAAO,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACJ"}
@@ -24,6 +24,8 @@ export interface SystemDatabase {
24
24
  recv<T extends NonNullable<any>>(workflowUUID: string, functionID: number, topic?: string, timeoutSeconds?: number): Promise<T | null>;
25
25
  setEvent<T extends NonNullable<any>>(workflowUUID: string, functionID: number, key: string, value: T): Promise<void>;
26
26
  getEvent<T extends NonNullable<any>>(workflowUUID: string, key: string, timeoutSeconds: number, callerUUID?: string, functionID?: number): Promise<T | null>;
27
+ getLastScheduledTime(wfn: string): Promise<number | null>;
28
+ setLastScheduledTime(wfn: string, invtime: number): Promise<number | null>;
27
29
  }
28
30
  export interface WorkflowStatusInternal {
29
31
  workflowUUID: string;
@@ -91,5 +93,7 @@ export declare class PostgresSystemDatabase implements SystemDatabase {
91
93
  * workflow listener by resolving its promise.
92
94
  */
93
95
  listenForNotifications(): Promise<void>;
96
+ getLastScheduledTime(wfn: string): Promise<number | null>;
97
+ setLastScheduledTime(wfn: string, invtime: number): Promise<number | null>;
94
98
  }
95
99
  //# sourceMappingURL=system_database.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"system_database.d.ts","sourceRoot":"","sources":["../../src/system_database.ts"],"names":[],"mappings":"AAGA,OAAO,EAA0B,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAiB,IAAI,EAAE,UAAU,EAAgB,UAAU,EAAU,MAAM,IAAI,CAAC;AAEvF,OAAO,EAAgB,cAAc,EAAE,MAAM,YAAY,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAI1D,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,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ler);
504
504
  }
505
+ /* SCHEDULER */
506
+ async getLastScheduledTime(wfn) {
507
+ const res = await this.pool.query(`
508
+ SELECT last_run_time
509
+ FROM ${dbos_executor_1.DBOSExecutor.systemDBSchemaName}.scheduler_state
510
+ WHERE workflow_fn_name = $1;
511
+ `, [wfn]);
512
+ let v = res.rows[0]?.last_run_time ?? null;
513
+ if (v !== null)
514
+ v = parseInt(`${v}`);
515
+ return v;
516
+ }
517
+ async setLastScheduledTime(wfn, invtime) {
518
+ const res = await this.pool.query(`
519
+ INSERT INTO ${dbos_executor_1.DBOSExecutor.systemDBSchemaName}.scheduler_state (workflow_fn_name, last_run_time)
520
+ VALUES ($1, $2)
521
+ ON CONFLICT (workflow_fn_name)
522
+ DO UPDATE SET last_run_time = GREATEST(EXCLUDED.last_run_time, scheduler_state.last_run_time)
523
+ RETURNING last_run_time;
524
+ `, [wfn, invtime]);
525
+ return parseInt(`${res.rows[0].last_run_time}`);
526
+ }
505
527
  }
506
528
  exports.PostgresSystemDatabase = PostgresSystemDatabase;
507
529
  //# sourceMappingURL=system_database.js.map