@yieldstar/sqlite-runtime 0.6.0 → 0.6.1
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/bun.js +1 -1
- package/dist/dao/executions-dao.d.ts +3 -2
- package/dist/dao/executions-dao.d.ts.map +1 -1
- package/dist/index-ekggxe8v.js +987 -0
- package/dist/index-t60e4kvz.js +988 -0
- package/dist/index.js +1 -1
- package/dist/node.js +1 -1
- package/dist/sqlite-execution.d.ts +2 -1
- package/dist/sqlite-execution.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/dao/executions-dao.ts +14 -3
- package/src/sqlite-execution.ts +6 -2
package/dist/index.js
CHANGED
package/dist/node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ExecutionAcknowledgeResult, type ExecutionAdmissionRequest, type ExecutionAdmissionResult, type ExecutionClient, type ExecutionLease, type ExecutionRecord, type ExecutionStartRequest, type ExecutionStartResult, type ExecutionReleaseResult, type ExecutionRenewResult, type ExecutionWakeResult, type WorkflowRunOutcome } from "@yieldstar/core";
|
|
1
|
+
import { type ExecutionAcknowledgeResult, type ExecutionAdmissionRequest, type ExecutionAdmissionResult, type ExecutionClaimFilter, type ExecutionClient, type ExecutionLease, type ExecutionRecord, type ExecutionStartRequest, type ExecutionStartResult, type ExecutionReleaseResult, type ExecutionRenewResult, type ExecutionWakeResult, type WorkflowRunOutcome } from "@yieldstar/core";
|
|
2
2
|
import type { SqliteDriver } from "./sqlite-driver";
|
|
3
3
|
export type SqliteExecutionClientOptions = {
|
|
4
4
|
/** Reads the current time. Defaults to `Date.now`. */
|
|
@@ -26,6 +26,7 @@ export declare class SqliteExecutionClient implements ExecutionClient {
|
|
|
26
26
|
claimDue(request: {
|
|
27
27
|
limit: number;
|
|
28
28
|
duration: number;
|
|
29
|
+
filter?: ExecutionClaimFilter;
|
|
29
30
|
}): Promise<ExecutionLease[]>;
|
|
30
31
|
renew(request: {
|
|
31
32
|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AAM,CAAC;QACjB,MAAM,CAAC,EAAE,oBAAoB,CAAC;KAC/B,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA6BvB,KAAK,CAAC,OAAO,EAAE;QACnB,KAAK,EAAE,cAAc,CAAC;QACtB,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAU3B,OAAO,CAAC,OAAO,EAAE;QACrB,KAAK,EAAE,cAAc,CAAC;KACvB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAM7B,WAAW,CAAC,OAAO,EAAE;QACzB,KAAK,EAAE,cAAc,CAAC;QACtB,OAAO,EAAE,kBAAkB,CAAC;KAC7B,GAAG,OAAO,CAAC,0BAA0B,CAAC;IAUvC;;;OAGG;IACH,OAAO,CAAC,UAAU;IAelB;;;;;OAKG;IACH,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,GAAE,MAAqB;CAOrE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yieldstar/sqlite-runtime",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Daniel Grant",
|
|
6
6
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"pino": "^9.9.0",
|
|
33
33
|
"uuid": "^11.1.0",
|
|
34
|
-
"@yieldstar/core": "0.6.
|
|
34
|
+
"@yieldstar/core": "0.6.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/bun": "^1.2.21",
|
|
@@ -76,17 +76,28 @@ export class ExecutionsDao {
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Up to `limit` claimable execution IDs, earliest due first. `now` is a
|
|
79
|
-
* millisecond Unix timestamp from the runtime clock.
|
|
79
|
+
* millisecond Unix timestamp from the runtime clock. When `executionIds` is
|
|
80
|
+
* given, only those executions are considered.
|
|
80
81
|
*/
|
|
81
|
-
getClaimableIds(
|
|
82
|
+
getClaimableIds(
|
|
83
|
+
now: number,
|
|
84
|
+
limit: number,
|
|
85
|
+
executionIds?: readonly string[]
|
|
86
|
+
) {
|
|
82
87
|
return this.db
|
|
83
88
|
.query<ExecutionIdRow>(
|
|
84
89
|
`SELECT execution_id FROM executions
|
|
85
90
|
WHERE next_claim_at IS NOT NULL AND next_claim_at <= $now
|
|
91
|
+
AND ($executionIds IS NULL
|
|
92
|
+
OR execution_id IN (SELECT value FROM json_each($executionIds)))
|
|
86
93
|
ORDER BY next_claim_at, execution_id
|
|
87
94
|
LIMIT $limit`
|
|
88
95
|
)
|
|
89
|
-
.all({
|
|
96
|
+
.all({
|
|
97
|
+
$now: now,
|
|
98
|
+
$limit: limit,
|
|
99
|
+
$executionIds: executionIds ? JSON.stringify(executionIds) : null,
|
|
100
|
+
})
|
|
90
101
|
.map((row) => row.execution_id);
|
|
91
102
|
}
|
|
92
103
|
|
package/src/sqlite-execution.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
type ExecutionAcknowledgeResult,
|
|
17
17
|
type ExecutionAdmissionRequest,
|
|
18
18
|
type ExecutionAdmissionResult,
|
|
19
|
+
type ExecutionClaimFilter,
|
|
19
20
|
type ExecutionClient,
|
|
20
21
|
type ExecutionLease,
|
|
21
22
|
type ExecutionRecord,
|
|
@@ -142,8 +143,10 @@ export class SqliteExecutionClient implements ExecutionClient {
|
|
|
142
143
|
async claimDue(request: {
|
|
143
144
|
limit: number;
|
|
144
145
|
duration: number;
|
|
146
|
+
filter?: ExecutionClaimFilter;
|
|
145
147
|
}): Promise<ExecutionLease[]> {
|
|
146
|
-
|
|
148
|
+
const executionIds = request.filter?.executionIds;
|
|
149
|
+
if (request.limit <= 0 || executionIds?.length === 0) return [];
|
|
147
150
|
// The IMMEDIATE transaction holds the write lock, so concurrent claims from
|
|
148
151
|
// any process sharing the file see each other's leases.
|
|
149
152
|
return runTransaction(this.db, () => {
|
|
@@ -152,7 +155,8 @@ export class SqliteExecutionClient implements ExecutionClient {
|
|
|
152
155
|
|
|
153
156
|
for (const executionId of this.executionsDao.getClaimableIds(
|
|
154
157
|
now,
|
|
155
|
-
request.limit
|
|
158
|
+
request.limit,
|
|
159
|
+
executionIds
|
|
156
160
|
)) {
|
|
157
161
|
const state = this.executionsDao.getState(executionId);
|
|
158
162
|
if (!state || !isExecutionClaimable(state, now)) continue;
|