@falcondev-oss/workflow 0.1.2 → 0.2.0
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/index.d.mts +5 -1
- package/dist/index.mjs +21 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import IORedis from "ioredis";
|
|
|
4
4
|
import { SuperJSONResult } from "superjson";
|
|
5
5
|
import { Options } from "p-retry";
|
|
6
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
|
-
import { SetOptional, Tagged } from "type-fest";
|
|
7
|
+
import { Except, SetOptional, Tagged } from "type-fest";
|
|
8
8
|
|
|
9
9
|
//#region src/errors.d.ts
|
|
10
10
|
declare class WorkflowInputError extends UnrecoverableError {
|
|
@@ -16,6 +16,7 @@ declare class WorkflowInputError extends UnrecoverableError {
|
|
|
16
16
|
declare const Settings: {
|
|
17
17
|
defaultPrefix: string;
|
|
18
18
|
defaultConnection: IORedis | undefined;
|
|
19
|
+
defaultCronTimezone: string | undefined;
|
|
19
20
|
};
|
|
20
21
|
//#endregion
|
|
21
22
|
//#region src/serializer.d.ts
|
|
@@ -85,6 +86,9 @@ declare class Workflow<RunInput, Input, Output> {
|
|
|
85
86
|
constructor(opts: WorkflowOptions<RunInput, Input, Output>);
|
|
86
87
|
work(opts?: Omit<SetOptional<WorkerOptions, 'connection'>, 'autorun'>): Promise<this>;
|
|
87
88
|
run(input: RunInput, opts?: JobsOptions): Promise<WorkflowJob<Output>>;
|
|
89
|
+
runIn(input: RunInput, delayMs: number, opts?: Except<JobsOptions, 'delay'>): Promise<WorkflowJob<Output>>;
|
|
90
|
+
runAt(input: RunInput, date: Date, opts?: Except<JobsOptions, 'delay'>): Promise<WorkflowJob<Output>>;
|
|
91
|
+
repeat(input: RunInput, cronOrInterval: string | number, opts?: Except<JobsOptions, 'repeat'>): Promise<WorkflowJob<Output>>;
|
|
88
92
|
private getOrCreateQueue;
|
|
89
93
|
private getOrCreateQueueEvents;
|
|
90
94
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,8 @@ var WorkflowInputError = class extends UnrecoverableError {
|
|
|
19
19
|
//#region src/settings.ts
|
|
20
20
|
const Settings = {
|
|
21
21
|
defaultPrefix: "falcondev-oss-workflow",
|
|
22
|
-
defaultConnection: void 0
|
|
22
|
+
defaultConnection: void 0,
|
|
23
|
+
defaultCronTimezone: void 0
|
|
23
24
|
};
|
|
24
25
|
const defaultRedisConnection = createSingletonPromise(async () => {
|
|
25
26
|
if (Settings.defaultConnection) return Settings.defaultConnection;
|
|
@@ -219,6 +220,25 @@ var Workflow = class {
|
|
|
219
220
|
queueEvents: await this.getOrCreateQueueEvents()
|
|
220
221
|
});
|
|
221
222
|
}
|
|
223
|
+
async runIn(input, delayMs, opts) {
|
|
224
|
+
return this.run(input, {
|
|
225
|
+
delay: delayMs,
|
|
226
|
+
...opts
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
async runAt(input, date, opts) {
|
|
230
|
+
const now = Date.now();
|
|
231
|
+
return date.getTime() < now ? this.run(input, opts) : this.runIn(input, date.getTime() - Date.now(), opts);
|
|
232
|
+
}
|
|
233
|
+
async repeat(input, cronOrInterval, opts) {
|
|
234
|
+
return this.run(input, {
|
|
235
|
+
repeat: {
|
|
236
|
+
tz: Settings.defaultCronTimezone,
|
|
237
|
+
...typeof cronOrInterval === "string" ? { pattern: cronOrInterval } : { every: cronOrInterval }
|
|
238
|
+
},
|
|
239
|
+
...opts
|
|
240
|
+
});
|
|
241
|
+
}
|
|
222
242
|
async getOrCreateQueue() {
|
|
223
243
|
if (!this.queue) this.queue = new Queue(this.opts.id, {
|
|
224
244
|
prefix: Settings.defaultPrefix,
|
package/package.json
CHANGED