@kubun/store-workflow 0.14.0 → 0.15.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/lib/api.d.ts +10 -0
- package/lib/api.js +32 -0
- package/package.json +5 -5
package/lib/api.d.ts
CHANGED
|
@@ -74,6 +74,15 @@ export type AdvanceScheduleAdaptiveInput = {
|
|
|
74
74
|
lastOutcome: string | null;
|
|
75
75
|
consecutiveCount: number;
|
|
76
76
|
};
|
|
77
|
+
export type UpsertAdaptiveScheduleInput = {
|
|
78
|
+
id: string;
|
|
79
|
+
workflowName: string;
|
|
80
|
+
params: unknown;
|
|
81
|
+
policy: unknown;
|
|
82
|
+
nextRun: number;
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
reactivate?: boolean;
|
|
85
|
+
};
|
|
77
86
|
export type WorkflowStoreAPI = {
|
|
78
87
|
insertInstance(input: InsertInstanceInput): Promise<InsertInstanceResult>;
|
|
79
88
|
claim(instanceID: string, bootID: string, leaseMs: number, now: number): Promise<WorkflowInstanceRow | null>;
|
|
@@ -88,6 +97,7 @@ export type WorkflowStoreAPI = {
|
|
|
88
97
|
get(instanceID: string): Promise<WorkflowInstanceRow | null>;
|
|
89
98
|
list(filter?: ListFilter): Promise<Array<WorkflowInstanceRow>>;
|
|
90
99
|
insertSchedule(input: InsertScheduleInput, now: number): Promise<void>;
|
|
100
|
+
upsertAdaptiveSchedule(input: UpsertAdaptiveScheduleInput, now: number): Promise<WorkflowScheduleRow>;
|
|
91
101
|
getSchedule(id: string): Promise<WorkflowScheduleRow | null>;
|
|
92
102
|
listSchedules(): Promise<Array<WorkflowScheduleRow>>;
|
|
93
103
|
listDueSchedules(now: number): Promise<Array<WorkflowScheduleRow>>;
|
package/lib/api.js
CHANGED
|
@@ -231,6 +231,38 @@ export function createWorkflowStore(db, adapter) {
|
|
|
231
231
|
updated_at: now
|
|
232
232
|
}).execute();
|
|
233
233
|
},
|
|
234
|
+
async upsertAdaptiveSchedule (input, now) {
|
|
235
|
+
const reactivate = input.reactivate ?? true;
|
|
236
|
+
// One statement, no preceding read: ON CONFLICT DO UPDATE lets two
|
|
237
|
+
// concurrent enables of the same id both commit — one inserts, the other
|
|
238
|
+
// updates — instead of the loser hitting the PK constraint. RETURNING
|
|
239
|
+
// hands back the row as committed by this statement. The update touches
|
|
240
|
+
// only next_run + enabled, so an existing row's params/policy and its
|
|
241
|
+
// last_outcome/consecutive_count streak survive a re-arm. Under
|
|
242
|
+
// reactivate:false the update keeps the stored `enabled` flag (a
|
|
243
|
+
// qualified self-reference, portable across SQLite and Postgres) so a
|
|
244
|
+
// user-paused row is not silently re-enabled; next_run still advances.
|
|
245
|
+
const row = await db.insertInto('kubun_workflow_schedules').values({
|
|
246
|
+
id: input.id,
|
|
247
|
+
workflow_name: input.workflowName,
|
|
248
|
+
params: encodeParams(input.params),
|
|
249
|
+
cron: null,
|
|
250
|
+
every: null,
|
|
251
|
+
kind: 'adaptive',
|
|
252
|
+
policy: encodePolicy(input.policy ?? null),
|
|
253
|
+
last_outcome: null,
|
|
254
|
+
consecutive_count: 0,
|
|
255
|
+
next_run: input.nextRun,
|
|
256
|
+
enabled: input.enabled ? 1 : 0,
|
|
257
|
+
created_at: now,
|
|
258
|
+
updated_at: now
|
|
259
|
+
}).onConflict((oc)=>oc.column('id').doUpdateSet((eb)=>({
|
|
260
|
+
next_run: input.nextRun,
|
|
261
|
+
enabled: reactivate ? input.enabled ? 1 : 0 : eb.ref('kubun_workflow_schedules.enabled'),
|
|
262
|
+
updated_at: now
|
|
263
|
+
}))).returningAll().executeTakeFirstOrThrow();
|
|
264
|
+
return rowToSchedule(row);
|
|
265
|
+
},
|
|
234
266
|
async getSchedule (id) {
|
|
235
267
|
const row = await db.selectFrom('kubun_workflow_schedules').selectAll().where('id', '=', id).executeTakeFirst();
|
|
236
268
|
return row != null ? rowToSchedule(row) : null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubun/store-workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"license": "see LICENSE.md",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"LICENSE.md"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@kubun/db": "^0.
|
|
19
|
-
"@kubun/db-adapter": "^0.
|
|
18
|
+
"@kubun/db": "^0.15.0",
|
|
19
|
+
"@kubun/db-adapter": "^0.15.0",
|
|
20
20
|
"kysely": "^0.29.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@kubun/db-better-sqlite": "^0.
|
|
24
|
-
"@kubun/db-postgres": "^0.
|
|
23
|
+
"@kubun/db-better-sqlite": "^0.15.0",
|
|
24
|
+
"@kubun/db-postgres": "^0.15.0",
|
|
25
25
|
"@testcontainers/postgresql": "^12.1.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|