@falcondev-oss/workflow 0.7.4 → 0.8.3
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 +15 -12
- package/dist/index.mjs +15 -14
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { Meter, Span } from "@opentelemetry/api";
|
|
|
4
4
|
import { SuperJSONResult } from "superjson";
|
|
5
5
|
import { Options } from "p-retry";
|
|
6
6
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
7
|
-
import { AddOptions, Job, Queue, QueueOptions, WorkerOptions } from "groupmq";
|
|
7
|
+
import { AddOptions, Job, Queue, QueueOptions, Worker, WorkerOptions } from "groupmq";
|
|
8
8
|
import { Except, IsUnknown, SetOptional, Tagged } from "type-fest";
|
|
9
9
|
|
|
10
10
|
//#region src/settings.d.ts
|
|
@@ -103,18 +103,21 @@ type WorkflowWorkerOptions<Input> = Except<WorkerOptions<WorkflowJobPayloadInter
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
declare class Workflow<RunInput, Input, Output> {
|
|
106
|
-
id: string;
|
|
107
|
-
private opts;
|
|
108
|
-
private queue?;
|
|
106
|
+
'id': string;
|
|
107
|
+
private 'opts';
|
|
108
|
+
private 'queue'?;
|
|
109
|
+
'~internal': {
|
|
110
|
+
getOrCreateQueue: () => Promise<WorkflowQueueInternal<Input>>;
|
|
111
|
+
};
|
|
109
112
|
constructor(opts: WorkflowOptions<RunInput, Input, Output>);
|
|
110
|
-
work(opts?: WorkflowWorkerOptions<Input>): Promise<
|
|
111
|
-
run(input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
112
|
-
runIn(input: RunInput, delayMs: number, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
113
|
-
runAt(input: RunInput, date: Date, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
114
|
-
runCron(scheduleId: string, cron: string, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
115
|
-
runEvery(scheduleId: string, everyMs: number, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
116
|
-
private getOrCreateQueue;
|
|
117
|
-
private setupMetrics;
|
|
113
|
+
'work'(opts?: WorkflowWorkerOptions<Input>): Promise<Worker<WorkflowJobPayloadInternal<Input>>>;
|
|
114
|
+
'run'(input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
115
|
+
'runIn'(input: RunInput, delayMs: number, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
116
|
+
'runAt'(input: RunInput, date: Date, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
117
|
+
'runCron'(scheduleId: string, cron: string, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
118
|
+
'runEvery'(scheduleId: string, everyMs: number, input: RunInput, opts?: WorkflowJobRunOptions<Input>): Promise<WorkflowJob<Output>>;
|
|
119
|
+
private 'getOrCreateQueue';
|
|
120
|
+
private 'setupMetrics';
|
|
118
121
|
}
|
|
119
122
|
interface WorkflowRunContext<Input> {
|
|
120
123
|
input: IsUnknown<Input> extends true ? undefined : Input;
|
package/dist/index.mjs
CHANGED
|
@@ -7294,7 +7294,7 @@ var require_parser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
7294
7294
|
}));
|
|
7295
7295
|
|
|
7296
7296
|
//#endregion
|
|
7297
|
-
//#region node_modules/.pnpm/groupmq@1.1.0_ioredis@5.
|
|
7297
|
+
//#region node_modules/.pnpm/groupmq@1.1.0_ioredis@5.9.2/node_modules/groupmq/dist/index.js
|
|
7298
7298
|
var import_parser = /* @__PURE__ */ __toESM$1(require_parser(), 1);
|
|
7299
7299
|
const __INLINED_LUA_SCRIPTS__ = {
|
|
7300
7300
|
"change-delay": "-- argv: ns, jobId, newDelayUntil, now\nlocal ns = KEYS[1]\nlocal jobId = ARGV[1]\nlocal newDelayUntil = tonumber(ARGV[2])\nlocal now = tonumber(ARGV[3])\n\nlocal jobKey = ns .. \":job:\" .. jobId\nlocal delayedKey = ns .. \":delayed\"\nlocal readyKey = ns .. \":ready\"\n\n-- Check if job exists\nlocal exists = redis.call(\"EXISTS\", jobKey)\nif exists == 0 then\n return 0\nend\n\nlocal groupId = redis.call(\"HGET\", jobKey, \"groupId\")\nif not groupId then\n return 0\nend\n\nlocal gZ = ns .. \":g:\" .. groupId\n\n-- Update job's delayUntil field\nredis.call(\"HSET\", jobKey, \"delayUntil\", tostring(newDelayUntil))\n\n-- Check if job is currently in delayed set\nlocal inDelayed = redis.call(\"ZSCORE\", delayedKey, jobId)\n\nif newDelayUntil > 0 and newDelayUntil > now then\n -- Job should be delayed\n redis.call(\"HSET\", jobKey, \"status\", \"delayed\")\n if inDelayed then\n -- Update existing delay\n redis.call(\"ZADD\", delayedKey, newDelayUntil, jobId)\n else\n -- Move to delayed\n redis.call(\"ZADD\", delayedKey, newDelayUntil, jobId)\n -- If this is the head job, remove group from ready\n local head = redis.call(\"ZRANGE\", gZ, 0, 0)\n if head and #head > 0 and head[1] == jobId then\n redis.call(\"ZREM\", readyKey, groupId)\n end\n end\nelse\n -- Job should be ready immediately\n redis.call(\"HSET\", jobKey, \"status\", \"waiting\")\n if inDelayed then\n -- Remove from delayed\n redis.call(\"ZREM\", delayedKey, jobId)\n -- If this is the head job, ensure group is in ready\n local head = redis.call(\"ZRANGE\", gZ, 0, 0, \"WITHSCORES\")\n if head and #head >= 2 and head[1] == jobId then\n local headScore = tonumber(head[2])\n redis.call(\"ZADD\", readyKey, headScore, groupId)\n end\n end\nend\n\nreturn 1\n\n\n",
|
|
@@ -9706,14 +9706,15 @@ var WorkflowStep = class WorkflowStep {
|
|
|
9706
9706
|
//#endregion
|
|
9707
9707
|
//#region src/workflow.ts
|
|
9708
9708
|
var Workflow = class {
|
|
9709
|
-
id;
|
|
9710
|
-
opts;
|
|
9711
|
-
queue;
|
|
9712
|
-
|
|
9709
|
+
"id";
|
|
9710
|
+
"opts";
|
|
9711
|
+
"queue";
|
|
9712
|
+
"~internal" = { getOrCreateQueue: this.getOrCreateQueue.bind(this) };
|
|
9713
|
+
"constructor"(opts) {
|
|
9713
9714
|
this.id = opts.id;
|
|
9714
9715
|
this.opts = opts;
|
|
9715
9716
|
}
|
|
9716
|
-
async work(opts) {
|
|
9717
|
+
async "work"(opts) {
|
|
9717
9718
|
const queue = await this.getOrCreateQueue();
|
|
9718
9719
|
const worker = new Worker({
|
|
9719
9720
|
handler: async (job) => {
|
|
@@ -9762,9 +9763,9 @@ var Workflow = class {
|
|
|
9762
9763
|
Settings.logger?.info?.(`[${this.opts.id}] Received ${signal}, shutting down worker...`);
|
|
9763
9764
|
await worker.close();
|
|
9764
9765
|
}, { wait: 1e4 });
|
|
9765
|
-
return
|
|
9766
|
+
return worker;
|
|
9766
9767
|
}
|
|
9767
|
-
async run(input, opts) {
|
|
9768
|
+
async "run"(input, opts) {
|
|
9768
9769
|
const parsedInput = this.opts.schema && await this.opts.schema["~standard"].validate(input);
|
|
9769
9770
|
if (parsedInput?.issues) throw new Error("Invalid workflow input");
|
|
9770
9771
|
const queue = await this.getOrCreateQueue();
|
|
@@ -9788,33 +9789,33 @@ var Workflow = class {
|
|
|
9788
9789
|
}) });
|
|
9789
9790
|
});
|
|
9790
9791
|
}
|
|
9791
|
-
async runIn(input, delayMs, opts) {
|
|
9792
|
+
async "runIn"(input, delayMs, opts) {
|
|
9792
9793
|
return this.run(input, {
|
|
9793
9794
|
delay: delayMs,
|
|
9794
9795
|
...opts
|
|
9795
9796
|
});
|
|
9796
9797
|
}
|
|
9797
|
-
async runAt(input, date, opts) {
|
|
9798
|
+
async "runAt"(input, date, opts) {
|
|
9798
9799
|
return this.run(input, {
|
|
9799
9800
|
runAt: date,
|
|
9800
9801
|
...opts
|
|
9801
9802
|
});
|
|
9802
9803
|
}
|
|
9803
|
-
async runCron(scheduleId, cron, input, opts) {
|
|
9804
|
+
async "runCron"(scheduleId, cron, input, opts) {
|
|
9804
9805
|
return this.run(input, {
|
|
9805
9806
|
groupId: scheduleId,
|
|
9806
9807
|
repeat: { pattern: cron },
|
|
9807
9808
|
...opts
|
|
9808
9809
|
});
|
|
9809
9810
|
}
|
|
9810
|
-
async runEvery(scheduleId, everyMs, input, opts) {
|
|
9811
|
+
async "runEvery"(scheduleId, everyMs, input, opts) {
|
|
9811
9812
|
return this.run(input, {
|
|
9812
9813
|
groupId: scheduleId,
|
|
9813
9814
|
repeat: { every: everyMs },
|
|
9814
9815
|
...opts
|
|
9815
9816
|
});
|
|
9816
9817
|
}
|
|
9817
|
-
async getOrCreateQueue() {
|
|
9818
|
+
async "getOrCreateQueue"() {
|
|
9818
9819
|
if (!this.queue) this.queue = new Queue({
|
|
9819
9820
|
namespace: this.opts.id,
|
|
9820
9821
|
redis: this.opts.redis ?? await defaultRedisConnection(),
|
|
@@ -9823,7 +9824,7 @@ var Workflow = class {
|
|
|
9823
9824
|
});
|
|
9824
9825
|
return this.queue;
|
|
9825
9826
|
}
|
|
9826
|
-
async setupMetrics({ meter, prefix }) {
|
|
9827
|
+
async "setupMetrics"({ meter, prefix }) {
|
|
9827
9828
|
const attributes = { workflow_id: this.opts.id };
|
|
9828
9829
|
const queue = await this.getOrCreateQueue();
|
|
9829
9830
|
const completedJobsGauge = meter.createObservableGauge(`${prefix}_workflow_completed_jobs`, { description: "Number of completed workflow jobs" });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@falcondev-oss/workflow",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.3",
|
|
5
5
|
"description": "Simple type-safe queue worker with durable execution using Redis.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": "github:falcondev-oss/workflow",
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"@antfu/utils": "^9.3.0",
|
|
38
38
|
"@opentelemetry/api": "^1.9.0",
|
|
39
39
|
"@standard-schema/spec": "^1.1.0",
|
|
40
|
-
"@types/node": "^25.0
|
|
40
|
+
"@types/node": "^25.1.0",
|
|
41
41
|
"exit-hook": "^5.0.1",
|
|
42
|
-
"
|
|
42
|
+
"groupmq": "^1.1.0",
|
|
43
|
+
"ioredis": "^5.9.2",
|
|
43
44
|
"p-retry": "^7.1.1",
|
|
44
45
|
"superjson": "^2.2.6",
|
|
45
|
-
"type-fest": "^5.
|
|
46
|
+
"type-fest": "^5.4.2"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@falcondev-oss/configs": "^5.0.2",
|
|
49
50
|
"@testcontainers/redis": "^11.11.0",
|
|
50
51
|
"arktype": "^2.1.29",
|
|
51
52
|
"eslint": "^9.39.2",
|
|
52
|
-
"
|
|
53
|
-
"prettier": "^3.7.4",
|
|
53
|
+
"prettier": "^3.8.1",
|
|
54
54
|
"rolldown": "1.0.0-rc.2",
|
|
55
55
|
"tsdown": "0.19.0-beta.5",
|
|
56
56
|
"tsx": "^4.21.0",
|
|
57
57
|
"typescript": "^5.9.3",
|
|
58
58
|
"vitest": "^4.0.18",
|
|
59
|
-
"zod": "^4.3.
|
|
59
|
+
"zod": "^4.3.6"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "tsdown",
|