openworkflow 0.6.2 → 0.6.4
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/README.md +1 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +19 -1
- package/dist/core/step.d.ts +3 -3
- package/dist/core/step.d.ts.map +1 -1
- package/dist/core/step.js +3 -3
- package/dist/execution.js +2 -2
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -62,6 +62,7 @@ For more details, check out our [docs](https://openworkflow.dev/docs).
|
|
|
62
62
|
- ✅ **Step memoization** - Never repeat completed work
|
|
63
63
|
- ✅ **Automatic retries** - Built-in exponential backoff
|
|
64
64
|
- ✅ **Long pauses** - Sleep for seconds or months
|
|
65
|
+
- ✅ **Scheduled runs** - Start workflows at a specific time
|
|
65
66
|
- ✅ **Parallel execution** - Run steps concurrently
|
|
66
67
|
- ✅ **No extra servers** - Uses your existing database
|
|
67
68
|
- ✅ **Dashboard included** - Monitor and debug workflows
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Backend } from "./backend.js";
|
|
2
|
+
import type { DurationString } from "./core/duration.js";
|
|
2
3
|
import type { StandardSchemaV1 } from "./core/schema.js";
|
|
3
4
|
import type { SchemaInput, SchemaOutput, WorkflowRun } from "./core/workflow.js";
|
|
4
5
|
import type { WorkflowFunction } from "./execution.js";
|
|
@@ -89,6 +90,12 @@ export declare class RunnableWorkflow<Input, Output, RunInput = Input> {
|
|
|
89
90
|
* `workflowDef.run()`.
|
|
90
91
|
*/
|
|
91
92
|
export interface WorkflowRunOptions {
|
|
93
|
+
/**
|
|
94
|
+
* Schedule the workflow run for a future time. When set, the run will stay
|
|
95
|
+
* pending until the timestamp is reached. Accepts an absolute Date or a
|
|
96
|
+
* duration string (e.g. "5m", "2 hours").
|
|
97
|
+
*/
|
|
98
|
+
availableAt?: Date | DurationString;
|
|
92
99
|
/**
|
|
93
100
|
* Set a deadline for the workflow run. If the workflow exceeds this deadline,
|
|
94
101
|
* it will be marked as failed.
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EACZ,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,YAAY,EAClB,MAAM,eAAe,CAAC;AAMvB,KAAK,oBAAoB,CAAC,OAAO,EAAE,KAAK,IAAI,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAGzE,KAAK,gBAAgB,CAAC,OAAO,EAAE,KAAK,IAAI,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,QAAQ,CAA0B;gBAE9B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AC,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAEzC,EAAE,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC;IAKzE;;;;;OAKG;IACG,GAAG,CACP,KAAK,CAAC,EAAE,QAAQ,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;CAGtC;AAMD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,GAAG,cAAc,CAAC;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,IAAI,CAAC;CACnB;AAsBD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,WAAW,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,qBAAa,iBAAiB,CAAC,MAAM;IACnC,OAAO,CAAC,OAAO,CAAU;IACzB,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,OAAO,CAAC,oBAAoB,CAAS;IACrC,OAAO,CAAC,eAAe,CAAS;gBAEpB,OAAO,EAAE,qBAAqB;IAO1C;;;;OAIG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,8BAA8B,GAAG,OAAO,CAAC,MAAM,CAAC;IA2CvE;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAK9B"}
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { calculateDateFromDuration } from "./core/step.js";
|
|
1
2
|
import { validateInput } from "./core/workflow.js";
|
|
2
3
|
import { WorkflowRegistry } from "./registry.js";
|
|
3
4
|
import { Worker } from "./worker.js";
|
|
@@ -66,7 +67,7 @@ export class OpenWorkflow {
|
|
|
66
67
|
config: {},
|
|
67
68
|
context: null,
|
|
68
69
|
input: parsedInput ?? null,
|
|
69
|
-
availableAt:
|
|
70
|
+
availableAt: resolveAvailableAt(options?.availableAt),
|
|
70
71
|
deadlineAt: options?.deadlineAt ?? null,
|
|
71
72
|
});
|
|
72
73
|
return new WorkflowRunHandle({
|
|
@@ -119,6 +120,23 @@ export class RunnableWorkflow {
|
|
|
119
120
|
return this.ow.runWorkflow(this.workflow.spec, input, options);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Resolve availableAt to an absolute Date or null.
|
|
125
|
+
* @param availableAt - Absolute Date or duration string
|
|
126
|
+
* @returns Absolute Date or null
|
|
127
|
+
* @throws {Error} When a duration string is invalid
|
|
128
|
+
*/
|
|
129
|
+
function resolveAvailableAt(availableAt) {
|
|
130
|
+
if (!availableAt)
|
|
131
|
+
return null;
|
|
132
|
+
if (availableAt instanceof Date)
|
|
133
|
+
return availableAt;
|
|
134
|
+
const result = calculateDateFromDuration(availableAt);
|
|
135
|
+
if (!result.ok) {
|
|
136
|
+
throw result.error;
|
|
137
|
+
}
|
|
138
|
+
return result.value;
|
|
139
|
+
}
|
|
122
140
|
/**
|
|
123
141
|
* Represents a started workflow run and provides methods to await its result.
|
|
124
142
|
* Returned from `workflowDef.run()`.
|
package/dist/core/step.d.ts
CHANGED
|
@@ -71,12 +71,12 @@ export declare function addToStepAttemptCache(cache: StepAttemptCache, attempt:
|
|
|
71
71
|
*/
|
|
72
72
|
export declare function normalizeStepOutput(result: unknown): JsonValue;
|
|
73
73
|
/**
|
|
74
|
-
* Calculate
|
|
75
|
-
* @param duration - The duration string to
|
|
74
|
+
* Calculate a future time from a duration string.
|
|
75
|
+
* @param duration - The duration string to add
|
|
76
76
|
* @param now - The current timestamp (defaults to Date.now())
|
|
77
77
|
* @returns A Result containing the resume Date or an Error
|
|
78
78
|
*/
|
|
79
|
-
export declare function
|
|
79
|
+
export declare function calculateDateFromDuration(duration: DurationString, now?: number): Result<Date>;
|
|
80
80
|
/**
|
|
81
81
|
* Create the context object for a sleep step attempt.
|
|
82
82
|
* @param resumeAt - The time when the sleep should resume
|
package/dist/core/step.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../core/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,SAAS,GACT,WAAW,GACX,WAAW,GACX,QAAQ,CAAC;AAEb;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACnC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,2BAA2B,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;I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GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG;IAC5D,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;CAClB,CAKA"}
|
package/dist/core/step.js
CHANGED
|
@@ -40,12 +40,12 @@ export function normalizeStepOutput(result) {
|
|
|
40
40
|
return (result ?? null);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Calculate
|
|
44
|
-
* @param duration - The duration string to
|
|
43
|
+
* Calculate a future time from a duration string.
|
|
44
|
+
* @param duration - The duration string to add
|
|
45
45
|
* @param now - The current timestamp (defaults to Date.now())
|
|
46
46
|
* @returns A Result containing the resume Date or an Error
|
|
47
47
|
*/
|
|
48
|
-
export function
|
|
48
|
+
export function calculateDateFromDuration(duration, now = Date.now()) {
|
|
49
49
|
const result = parseDuration(duration);
|
|
50
50
|
if (!result.ok) {
|
|
51
51
|
return err(result.error);
|
package/dist/execution.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { serializeError } from "./core/error.js";
|
|
2
|
-
import { createStepAttemptCacheFromAttempts, getCachedStepAttempt, addToStepAttemptCache, normalizeStepOutput,
|
|
2
|
+
import { createStepAttemptCacheFromAttempts, getCachedStepAttempt, addToStepAttemptCache, normalizeStepOutput, calculateDateFromDuration, createSleepContext, } from "./core/step.js";
|
|
3
3
|
/**
|
|
4
4
|
* Signal thrown when a workflow needs to sleep. Contains the time when the
|
|
5
5
|
* workflow should resume.
|
|
@@ -75,7 +75,7 @@ class StepExecutor {
|
|
|
75
75
|
if (existingAttempt)
|
|
76
76
|
return;
|
|
77
77
|
// create new step attempt for the sleep
|
|
78
|
-
const result =
|
|
78
|
+
const result = calculateDateFromDuration(duration);
|
|
79
79
|
if (!result.ok) {
|
|
80
80
|
throw result.error;
|
|
81
81
|
}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type { Workflow } from "./workflow.js";
|
|
2
2
|
export { isWorkflow } from "./workflow.js";
|
|
3
|
-
export
|
|
3
|
+
export * from "./backend.js";
|
|
4
4
|
export type { WorkflowRun, WorkflowRunStatus } from "./core/workflow.js";
|
|
5
5
|
export type { StepAttempt, StepAttemptStatus, StepKind } from "./core/step.js";
|
|
6
6
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../internal.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,cAAc,cAAc,CAAC;AAG7B,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACzE,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/internal.js
CHANGED