@plitzi/sdk-actions 0.39.10 → 0.39.11
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/CHANGELOG.md +10 -0
- package/dist/chunks/{load-qeEXWO8c.mjs → load-Dhjk46sd.mjs} +1 -1
- package/dist/chunks/{module-BP0LBhlj.mjs → module-BejdMWyt.mjs} +2 -1
- package/dist/chunks/{queueDocument-veQsE-_i.mjs → queueDocument-wwfFHQvw.mjs} +1 -1
- package/dist/chunks/{queueRules-C6jJo_yv.mjs → queueRules-DCW5x5as.mjs} +46 -3
- package/dist/chunks/{taskCatalog-Dp8XjA8_.mjs → taskCatalog-Crx-1ixP.mjs} +1 -1
- package/dist/engine/jobs/jobGroups.d.ts +7 -0
- package/dist/functions/index.mjs +2 -2
- package/dist/index.mjs +4 -4
- package/dist/mongo/index.mjs +72 -9
- package/dist/mongo/jobLists.d.ts +19 -0
- package/dist/mysql/index.mjs +101 -21
- package/dist/mysql/jobLists.d.ts +18 -0
- package/dist/mysql/rows.d.ts +5 -0
- package/dist/sqlite/index.mjs +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/jobs.d.ts +25 -0
- package/dist/worker/index.mjs +3 -3
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @plitzi/sdk-actions
|
|
2
2
|
|
|
3
|
+
## 0.39.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d0b5be6: Released with every `@plitzi` package at this version. What changed in each, and what to do when you upgrade, is in
|
|
8
|
+
`@plitzi/cli`'s `CHANGELOG.md`: one copy of the notes, not one per package.
|
|
9
|
+
- Updated dependencies [d0b5be6]
|
|
10
|
+
- @plitzi/sdk-kernel@0.39.11
|
|
11
|
+
- @plitzi/sdk-shared@0.39.11
|
|
12
|
+
|
|
3
13
|
## 0.39.10
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as buildFunctions } from "./module-
|
|
1
|
+
import { i as buildFunctions } from "./module-BejdMWyt.mjs";
|
|
2
2
|
import { isRecord } from "@plitzi/sdk-shared/helpers";
|
|
3
3
|
import { readFunctionsSource } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
import { readFile, readdir } from "node:fs/promises";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as emptyState, o as queueOver, p as SET_ASIDE_WORDS, r as applyRule, s as queueRules } from "./queueRules-
|
|
1
|
+
import { a as emptyState, o as queueOver, p as SET_ASIDE_WORDS, r as applyRule, s as queueRules } from "./queueRules-DCW5x5as.mjs";
|
|
2
2
|
import { a as triggerParams, i as findTriggerNode, n as RunLimitReached, r as limitOf, t as ActionRunError } from "./errors-bCBfIe7c.mjs";
|
|
3
3
|
import { i as KV_METHODS, n as MAX_GRANT_SECONDS, o as createMemoryKv, t as DEFAULT_GRANT_SECONDS } from "./grants-BsD-WlLE.mjs";
|
|
4
4
|
import { cappedResponse, fetchOutbound, isBlockedHost } from "@plitzi/sdk-kernel/outbound";
|
|
@@ -422,6 +422,7 @@ var JOB_QUEUE_METHODS = {
|
|
|
422
422
|
advanceSchedule: true,
|
|
423
423
|
putSchedules: true,
|
|
424
424
|
listJobs: true,
|
|
425
|
+
listJobGroups: true,
|
|
425
426
|
listAcross: true,
|
|
426
427
|
summarize: true,
|
|
427
428
|
countDue: true,
|
|
@@ -53,6 +53,37 @@ var flowOf = (jobs, from, to) => {
|
|
|
53
53
|
};
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
|
+
// src/engine/jobs/jobGroups.ts
|
|
57
|
+
/**
|
|
58
|
+
* Jobs, the most recently touched first, as `JobQueue.listJobGroups` answers them: a group per space, work and status,
|
|
59
|
+
* in the order their latest jobs come — what the in-process stores' rules (`queueRules`) page.
|
|
60
|
+
*/
|
|
61
|
+
var groupJobs = (newestFirst) => {
|
|
62
|
+
const groups = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const job of newestFirst) {
|
|
64
|
+
const key = [
|
|
65
|
+
job.spaceId,
|
|
66
|
+
job.target.kind,
|
|
67
|
+
job.target.name,
|
|
68
|
+
job.status
|
|
69
|
+
].join("\0");
|
|
70
|
+
const group = groups.get(key);
|
|
71
|
+
if (group) {
|
|
72
|
+
group.count += 1;
|
|
73
|
+
group.firstDueAt = Math.min(group.firstDueAt, job.dueAt);
|
|
74
|
+
group.lastDueAt = Math.max(group.lastDueAt, job.dueAt);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const { state: _state, ...latest } = job;
|
|
78
|
+
groups.set(key, {
|
|
79
|
+
latest,
|
|
80
|
+
count: 1,
|
|
81
|
+
firstDueAt: job.dueAt,
|
|
82
|
+
lastDueAt: job.dueAt
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return [...groups.values()];
|
|
86
|
+
};
|
|
56
87
|
// src/engine/jobs/memoryNeeds.ts
|
|
57
88
|
/**
|
|
58
89
|
* What a job needs once the worker running it died, in the words every store writes: the in-process ones through
|
|
@@ -130,6 +161,8 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
|
|
|
130
161
|
const job = jobs.get(jobId);
|
|
131
162
|
return job && spaceIds.includes(job.spaceId) ? job : void 0;
|
|
132
163
|
};
|
|
164
|
+
/** What `listJobs` and `listJobGroups` read: the jobs a query names, the most recently touched first. */
|
|
165
|
+
const listed = ({ spaceIds, name, status, kind }) => [...jobs.values()].filter((job) => spaceIds.includes(job.spaceId) && (name === void 0 || job.target.name === name) && (status === void 0 || job.status === status) && (kind === void 0 || job.target.kind === kind)).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
133
166
|
/** Numbered by the history itself, not by `attempts`: an operator who repeats a finished job starts its attempt
|
|
134
167
|
* count again, and the record of what has already been tried must not start again with it. */
|
|
135
168
|
const appendAttempt = (job, attempt) => {
|
|
@@ -285,13 +318,22 @@ var queueRules = ({ jobs, schedules }, { retainFinished, clock, onUnansweredChan
|
|
|
285
318
|
});
|
|
286
319
|
}
|
|
287
320
|
},
|
|
288
|
-
listJobs: (
|
|
289
|
-
const matching =
|
|
321
|
+
listJobs: (query) => {
|
|
322
|
+
const matching = listed(query);
|
|
290
323
|
return {
|
|
291
|
-
jobs: matching.slice(offset, offset + limit).map((job) => ({ ...job })),
|
|
324
|
+
jobs: matching.slice(query.offset, query.offset + query.limit).map((job) => ({ ...job })),
|
|
292
325
|
total: matching.length
|
|
293
326
|
};
|
|
294
327
|
},
|
|
328
|
+
listJobGroups: (query) => {
|
|
329
|
+
const matching = listed(query);
|
|
330
|
+
const groups = groupJobs(matching);
|
|
331
|
+
return {
|
|
332
|
+
groups: groups.slice(query.offset, query.offset + query.limit),
|
|
333
|
+
total: groups.length,
|
|
334
|
+
jobs: matching.length
|
|
335
|
+
};
|
|
336
|
+
},
|
|
295
337
|
listAcross: ({ statuses, limit, order, environment }) => [...jobs.values()].filter((job) => statuses.includes(job.status) && (environment === void 0 || job.environment === environment)).sort((a, b) => order === "due" ? a.runAt - b.runAt : b.updatedAt - a.updatedAt).slice(0, limit).map((job) => ({ ...job })),
|
|
296
338
|
summarize: ({ spaces = 10 } = {}) => summarizeJobs([...jobs.values()], spaces),
|
|
297
339
|
countDue: ({ spaces, memoryMb } = {}) => {
|
|
@@ -520,6 +562,7 @@ var queueOver = (access) => ({
|
|
|
520
562
|
advanceSchedule: (...args) => access("advanceSchedule", args),
|
|
521
563
|
putSchedules: (...args) => access("putSchedules", args),
|
|
522
564
|
listJobs: (...args) => access("listJobs", args),
|
|
565
|
+
listJobGroups: (...args) => access("listJobGroups", args),
|
|
523
566
|
listAcross: (...args) => access("listAcross", args),
|
|
524
567
|
summarize: (...args) => access("summarize", args),
|
|
525
568
|
countDue: (...args) => access("countDue", args),
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { JobGroup } from '../../types';
|
|
2
|
+
import { Job } from '@plitzi/sdk-shared';
|
|
3
|
+
/**
|
|
4
|
+
* Jobs, the most recently touched first, as `JobQueue.listJobGroups` answers them: a group per space, work and status,
|
|
5
|
+
* in the order their latest jobs come — what the in-process stores' rules (`queueRules`) page.
|
|
6
|
+
*/
|
|
7
|
+
export declare const groupJobs: (newestFirst: readonly Job[]) => JobGroup[];
|
package/dist/functions/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as oauthCallbackUrlOn, d as DEFAULT_FUNCTION_LIMITS, i as buildFunctions, l as readManifest, n as functionsInHand, o as DEFAULT_FUNCTION_JOB_LIMITS, r as FunctionsBuildError, t as createActionsModule, u as DEFAULT_FUNCTION_CEILINGS } from "../chunks/module-
|
|
2
|
-
import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-
|
|
1
|
+
import { c as oauthCallbackUrlOn, d as DEFAULT_FUNCTION_LIMITS, i as buildFunctions, l as readManifest, n as functionsInHand, o as DEFAULT_FUNCTION_JOB_LIMITS, r as FunctionsBuildError, t as createActionsModule, u as DEFAULT_FUNCTION_CEILINGS } from "../chunks/module-BejdMWyt.mjs";
|
|
2
|
+
import { i as readFunctionsDir, n as loadFunctions, r as loadFunctionsSource } from "../chunks/load-Dhjk46sd.mjs";
|
|
3
3
|
import { t as credentialsFromEnv } from "../chunks/credentials-DwxZeAvH.mjs";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { FUNCTIONS_PROTOCOL, FunctionFailure, failedAnswerOf, readResponseMessage } from "@plitzi/sdk-shared/functions";
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, I as fetchConnectorRecords, L as rebaseMedia, M as KEPT_CALLS_PER_SPACE, N as KEPT_CALL_MS, O as scheduleFor, R as writeConnectorRecord, T as createJobWorker, _ as DEFAULT_LIMITS, a as createTaskRegistry, b as MAX_LIST_ENTRIES, f as taskName, g as spaceKvPatterns, j as createMemoryJobQueue, k as scheduleJobId, m as createSigning, p as MIN_SIGNING_SECRET_LENGTH, s as jobViewOf, t as createActionsModule, v as createKvStore, w as fleetKv, x as createActionJobs, y as MAX_LIST_BYTES } from "./chunks/module-
|
|
2
|
-
import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-
|
|
3
|
-
import { n as stateOf, t as documentOf } from "./chunks/queueDocument-
|
|
4
|
-
import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-
|
|
1
|
+
import { A as schedulesFor, C as fleetJobQueue, D as DEFAULT_MAX_ATTEMPTS, E as createScheduler, I as fetchConnectorRecords, L as rebaseMedia, M as KEPT_CALLS_PER_SPACE, N as KEPT_CALL_MS, O as scheduleFor, R as writeConnectorRecord, T as createJobWorker, _ as DEFAULT_LIMITS, a as createTaskRegistry, b as MAX_LIST_ENTRIES, f as taskName, g as spaceKvPatterns, j as createMemoryJobQueue, k as scheduleJobId, m as createSigning, p as MIN_SIGNING_SECRET_LENGTH, s as jobViewOf, t as createActionsModule, v as createKvStore, w as fleetKv, x as createActionJobs, y as MAX_LIST_BYTES } from "./chunks/module-BejdMWyt.mjs";
|
|
2
|
+
import { n as describeTask, r as createConnectorResolver, t as describeCatalog } from "./chunks/taskCatalog-Crx-1ixP.mjs";
|
|
3
|
+
import { n as stateOf, t as documentOf } from "./chunks/queueDocument-wwfFHQvw.mjs";
|
|
4
|
+
import { a as emptyState, i as changedBy, l as statusCounts, o as queueOver, r as applyRule, s as queueRules } from "./chunks/queueRules-DCW5x5as.mjs";
|
|
5
5
|
import { a as triggerParams, t as ActionRunError } from "./chunks/errors-bCBfIe7c.mjs";
|
|
6
6
|
import { a as createMapKv, o as createMemoryKv } from "./chunks/grants-BsD-WlLE.mjs";
|
|
7
7
|
import { createActionRealtime, n as publishJobView, r as createRealtimeHub, t as createRealtimeRetained } from "./realtime/index.mjs";
|
package/dist/mongo/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as flowOf, d as LOST_ERROR, f as LOST_MEMORY_WORDS, l as statusCounts, n as WAITING_STATUSES, p as SET_ASIDE_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-
|
|
1
|
+
import { _ as flowOf, d as LOST_ERROR, f as LOST_MEMORY_WORDS, l as statusCounts, n as WAITING_STATUSES, p as SET_ASIDE_WORDS, t as NEEDING_STATUSES, u as waitingKindOf } from "../chunks/queueRules-DCW5x5as.mjs";
|
|
2
2
|
import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
|
|
3
3
|
import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
// src/mongo/claimable.ts
|
|
@@ -56,6 +56,63 @@ var dropWaiting = async (jobs, { spaceIds, status, kind, name }, at, expiresAt)
|
|
|
56
56
|
functionJobs: watched.map((job) => job._id)
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
+
// src/mongo/jobLists.ts
|
|
60
|
+
/** The jobs a list names (`listJobs`, `listJobGroups`). */
|
|
61
|
+
var listFilter = ({ spaceIds, name, status, kind }) => ({
|
|
62
|
+
spaceId: { $in: spaceIds },
|
|
63
|
+
...name ? { "target.name": name } : {},
|
|
64
|
+
...status ? { status } : {},
|
|
65
|
+
...kind ? { "target.kind": kind } : {}
|
|
66
|
+
});
|
|
67
|
+
/**
|
|
68
|
+
* `JobQueue.listJobGroups` over the jobs' collection, in one pass — the page and the count alike: a group per space,
|
|
69
|
+
* work and status, the one of the most recently touched job first. What a job of the functions saved is left out before
|
|
70
|
+
* the grouping: up to megabytes per job, and no row shows it.
|
|
71
|
+
*/
|
|
72
|
+
var listJobGroupsOf = async (jobs, query) => {
|
|
73
|
+
const [found] = await jobs.aggregate([
|
|
74
|
+
{ $match: listFilter(query) },
|
|
75
|
+
{ $project: { state: 0 } },
|
|
76
|
+
{ $sort: {
|
|
77
|
+
updatedAt: -1,
|
|
78
|
+
_id: -1
|
|
79
|
+
} },
|
|
80
|
+
{ $group: {
|
|
81
|
+
_id: {
|
|
82
|
+
spaceId: "$spaceId",
|
|
83
|
+
kind: "$target.kind",
|
|
84
|
+
name: "$target.name",
|
|
85
|
+
status: "$status"
|
|
86
|
+
},
|
|
87
|
+
latest: { $first: "$$ROOT" },
|
|
88
|
+
count: { $sum: 1 },
|
|
89
|
+
firstDueAt: { $min: "$dueAt" },
|
|
90
|
+
lastDueAt: { $max: "$dueAt" }
|
|
91
|
+
} },
|
|
92
|
+
{ $sort: {
|
|
93
|
+
"latest.updatedAt": -1,
|
|
94
|
+
"latest._id": -1
|
|
95
|
+
} },
|
|
96
|
+
{ $facet: {
|
|
97
|
+
page: [
|
|
98
|
+
{ $skip: query.offset },
|
|
99
|
+
{ $limit: Math.max(1, query.limit) },
|
|
100
|
+
{ $project: { _id: 0 } }
|
|
101
|
+
],
|
|
102
|
+
total: [{ $group: {
|
|
103
|
+
_id: null,
|
|
104
|
+
groups: { $sum: 1 },
|
|
105
|
+
jobs: { $sum: "$count" }
|
|
106
|
+
} }]
|
|
107
|
+
} }
|
|
108
|
+
]).toArray();
|
|
109
|
+
const total = found.total.at(0);
|
|
110
|
+
return {
|
|
111
|
+
groups: found.page.slice(0, query.limit),
|
|
112
|
+
total: total?.groups ?? 0,
|
|
113
|
+
jobs: total?.jobs ?? 0
|
|
114
|
+
};
|
|
115
|
+
};
|
|
59
116
|
// src/mongo/jobQueue.ts
|
|
60
117
|
/** Mongo's code for a unique index that refused a second document with the same key. */
|
|
61
118
|
var DUPLICATE_KEY$1 = 11e3;
|
|
@@ -420,23 +477,29 @@ var createMongoJobQueue = ({ db, collections: names = {}, retentionDays = 90 })
|
|
|
420
477
|
actionId: { $nin: incoming.map((schedule) => schedule.actionId) }
|
|
421
478
|
});
|
|
422
479
|
},
|
|
423
|
-
listJobs: async (
|
|
480
|
+
listJobs: async (query) => {
|
|
424
481
|
const { jobs } = await collections();
|
|
425
|
-
const filter =
|
|
426
|
-
spaceId: { $in: spaceIds },
|
|
427
|
-
...name ? { "target.name": name } : {},
|
|
428
|
-
...status ? { status } : {},
|
|
429
|
-
...kind ? { "target.kind": kind } : {}
|
|
430
|
-
};
|
|
482
|
+
const filter = listFilter(query);
|
|
431
483
|
const [found, total] = await Promise.all([jobs.find(filter).sort({
|
|
432
484
|
updatedAt: -1,
|
|
433
485
|
_id: -1
|
|
434
|
-
}).skip(offset).limit(limit).toArray(), jobs.countDocuments(filter)]);
|
|
486
|
+
}).skip(query.offset).limit(query.limit).toArray(), jobs.countDocuments(filter)]);
|
|
435
487
|
return {
|
|
436
488
|
jobs: found.map(toJob),
|
|
437
489
|
total
|
|
438
490
|
};
|
|
439
491
|
},
|
|
492
|
+
listJobGroups: async (query) => {
|
|
493
|
+
const { jobs } = await collections();
|
|
494
|
+
const { groups, ...counted } = await listJobGroupsOf(jobs, query);
|
|
495
|
+
return {
|
|
496
|
+
...counted,
|
|
497
|
+
groups: groups.map(({ latest, ...group }) => ({
|
|
498
|
+
...group,
|
|
499
|
+
latest: toJob(latest)
|
|
500
|
+
}))
|
|
501
|
+
};
|
|
502
|
+
},
|
|
440
503
|
listAcross: async ({ statuses, limit, order, environment }) => {
|
|
441
504
|
const { jobs } = await collections();
|
|
442
505
|
return (await jobs.find({
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { JobDocument } from './jobQueue';
|
|
2
|
+
import { JobGroup, JobQuery } from '../types';
|
|
3
|
+
import { Collection, Filter } from 'mongodb';
|
|
4
|
+
/** The jobs a list names (`listJobs`, `listJobGroups`). */
|
|
5
|
+
export declare const listFilter: ({ spaceIds, name, status, kind }: JobQuery) => Filter<JobDocument>;
|
|
6
|
+
/** A group as the collection answers it: its latest job still a document. */
|
|
7
|
+
export type JobGroupDocument = Omit<JobGroup, 'latest'> & {
|
|
8
|
+
latest: JobDocument;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* `JobQueue.listJobGroups` over the jobs' collection, in one pass — the page and the count alike: a group per space,
|
|
12
|
+
* work and status, the one of the most recently touched job first. What a job of the functions saved is left out before
|
|
13
|
+
* the grouping: up to megabytes per job, and no row shows it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const listJobGroupsOf: (jobs: Collection<JobDocument>, query: JobQuery) => Promise<{
|
|
16
|
+
groups: JobGroupDocument[];
|
|
17
|
+
total: number;
|
|
18
|
+
jobs: number;
|
|
19
|
+
}>;
|
package/dist/mysql/index.mjs
CHANGED
|
@@ -1,8 +1,43 @@
|
|
|
1
|
-
import { _ as flowOf, d as LOST_ERROR, g as outgrewWorker, h as needsAfterLoss, l as statusCounts, m as lostError, p as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-
|
|
1
|
+
import { _ as flowOf, d as LOST_ERROR, g as outgrewWorker, h as needsAfterLoss, l as statusCounts, m as lostError, p as SET_ASIDE_WORDS, u as waitingKindOf } from "../chunks/queueRules-DCW5x5as.mjs";
|
|
2
2
|
import { t as createStoreClock } from "../chunks/storeClock-Btm7EaVm.mjs";
|
|
3
3
|
import { TERMINAL_JOB_STATUSES } from "@plitzi/sdk-shared/actions";
|
|
4
4
|
import { execute, selectOne, selectRows } from "@plitzi/sdk-kernel/mysql";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* A job's row as a list reads it: every column but what a job of the functions saved (`state`, up to megabytes, and no
|
|
7
|
+
* list shows it) — read as NULL, so `toJob` reads it as none.
|
|
8
|
+
*/
|
|
9
|
+
var LISTED_JOB_COLUMNS = [...Object.keys({
|
|
10
|
+
id: true,
|
|
11
|
+
space_id: true,
|
|
12
|
+
target_kind: true,
|
|
13
|
+
target_name: true,
|
|
14
|
+
target: true,
|
|
15
|
+
environment: true,
|
|
16
|
+
input: true,
|
|
17
|
+
due_at: true,
|
|
18
|
+
max_attempts: true,
|
|
19
|
+
missed: true,
|
|
20
|
+
job_key: true,
|
|
21
|
+
status: true,
|
|
22
|
+
run_at: true,
|
|
23
|
+
attempts: true,
|
|
24
|
+
lease_until: true,
|
|
25
|
+
worker_id: true,
|
|
26
|
+
run_id: true,
|
|
27
|
+
cancel_requested: true,
|
|
28
|
+
created_at: true,
|
|
29
|
+
updated_at: true,
|
|
30
|
+
error: true,
|
|
31
|
+
history: true,
|
|
32
|
+
state: true,
|
|
33
|
+
progress: true,
|
|
34
|
+
result: true,
|
|
35
|
+
pause_requested: true,
|
|
36
|
+
active_ms: true,
|
|
37
|
+
holder_memory_mb: true,
|
|
38
|
+
needs_memory_mb: true,
|
|
39
|
+
near_memory_limit: true
|
|
40
|
+
}).filter((column) => column !== "state"), "NULL AS state"].join(", ");
|
|
6
41
|
/**
|
|
7
42
|
* A row as the contract shapes it.
|
|
8
43
|
*
|
|
@@ -79,6 +114,57 @@ var claimable = (at, spaces, memoryMb, takes) => {
|
|
|
79
114
|
]
|
|
80
115
|
};
|
|
81
116
|
};
|
|
117
|
+
// src/mysql/jobLists.ts
|
|
118
|
+
/** Digits an epoch-ms `updated_at` is padded to, so its text sorts as the number does. */
|
|
119
|
+
var LATEST_PAD = 20;
|
|
120
|
+
/** The jobs a list names (`listJobs`, `listJobGroups`): the clause and its parameters. */
|
|
121
|
+
var listWhere = ({ spaceIds, name, status, kind }) => ({
|
|
122
|
+
sql: [
|
|
123
|
+
"space_id IN (?)",
|
|
124
|
+
...name ? ["target_name = ?"] : [],
|
|
125
|
+
...status ? ["status = ?"] : [],
|
|
126
|
+
...kind ? ["target_kind = ?"] : []
|
|
127
|
+
].join(" AND "),
|
|
128
|
+
params: [
|
|
129
|
+
spaceIds,
|
|
130
|
+
...name ? [name] : [],
|
|
131
|
+
...status ? [status] : [],
|
|
132
|
+
...kind ? [kind] : []
|
|
133
|
+
]
|
|
134
|
+
});
|
|
135
|
+
/**
|
|
136
|
+
* `JobQueue.listJobGroups` over the jobs table: a group per space, work and status, the one of the most recently
|
|
137
|
+
* touched job first. Each group's latest job — by `updated_at`, then `id`, as `listJobs` orders them — is read off one
|
|
138
|
+
* MAX of the two written as one string: MySQL 5.7 has no window functions. A query naming no space is answered empty
|
|
139
|
+
* by the caller (`IN ()` is not SQL).
|
|
140
|
+
*/
|
|
141
|
+
var listJobGroupsOf = async (conn, table, query) => {
|
|
142
|
+
const where = listWhere(query);
|
|
143
|
+
const grouped = `FROM ${table} WHERE ${where.sql} GROUP BY space_id, target_kind, target_name, status`;
|
|
144
|
+
const [found, count] = await Promise.all([selectRows(conn, `SELECT MAX(CONCAT(LPAD(updated_at, ${String(LATEST_PAD)}, '0'), id)) AS latest, COUNT(*) AS n,
|
|
145
|
+
MIN(due_at) AS first_due, MAX(due_at) AS last_due
|
|
146
|
+
${grouped} ORDER BY latest DESC LIMIT ? OFFSET ?`, [
|
|
147
|
+
...where.params,
|
|
148
|
+
query.limit,
|
|
149
|
+
query.offset
|
|
150
|
+
]), selectOne(conn, `SELECT COUNT(*) AS total, SUM(n) AS jobs FROM (SELECT COUNT(*) AS n ${grouped}) AS g`, where.params)]);
|
|
151
|
+
const ids = found.map((group) => group.latest.slice(LATEST_PAD));
|
|
152
|
+
const rows = ids.length > 0 ? await selectRows(conn, `SELECT ${LISTED_JOB_COLUMNS} FROM ${table} WHERE id IN (?)`, [ids]) : [];
|
|
153
|
+
const latest = new Map(rows.map((row) => [row.id, toJob(row)]));
|
|
154
|
+
return {
|
|
155
|
+
groups: found.flatMap((group, at) => {
|
|
156
|
+
const job = latest.get(ids[at] ?? "");
|
|
157
|
+
return job ? [{
|
|
158
|
+
latest: job,
|
|
159
|
+
count: Number(group.n),
|
|
160
|
+
firstDueAt: Number(group.first_due),
|
|
161
|
+
lastDueAt: Number(group.last_due)
|
|
162
|
+
}] : [];
|
|
163
|
+
}),
|
|
164
|
+
total: Number(count?.total ?? 0),
|
|
165
|
+
jobs: Number(count?.jobs ?? 0)
|
|
166
|
+
};
|
|
167
|
+
};
|
|
82
168
|
// src/mysql/schema.ts
|
|
83
169
|
var PREFIX = /^[A-Za-z0-9_]*$/;
|
|
84
170
|
/**
|
|
@@ -556,34 +642,28 @@ var createMysqlJobQueue = ({ pool, tablePrefix = "", createTables = true, retent
|
|
|
556
642
|
await execute(connection, kept.length > 0 ? `DELETE FROM ${t.schedules} WHERE space_id = ? AND action_id NOT IN (?)` : `DELETE FROM ${t.schedules} WHERE space_id = ?`, kept.length > 0 ? [spaceId, kept] : [spaceId]);
|
|
557
643
|
});
|
|
558
644
|
},
|
|
559
|
-
listJobs: async (
|
|
560
|
-
if (!inSpaces(spaceIds)) return {
|
|
645
|
+
listJobs: async (query) => {
|
|
646
|
+
if (!inSpaces(query.spaceIds)) return {
|
|
561
647
|
jobs: [],
|
|
562
648
|
total: 0
|
|
563
649
|
};
|
|
564
650
|
const conn = await db();
|
|
565
|
-
const where =
|
|
566
|
-
|
|
567
|
-
...
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
]
|
|
571
|
-
const params = [
|
|
572
|
-
spaceIds,
|
|
573
|
-
...name ? [name] : [],
|
|
574
|
-
...status ? [status] : [],
|
|
575
|
-
...kind ? [kind] : []
|
|
576
|
-
];
|
|
577
|
-
const [rows, count] = await Promise.all([selectRows(conn, `SELECT * FROM ${t.jobs} WHERE ${where} ORDER BY updated_at DESC, id DESC LIMIT ? OFFSET ?`, [
|
|
578
|
-
...params,
|
|
579
|
-
limit,
|
|
580
|
-
offset
|
|
581
|
-
]), selectOne(conn, `SELECT COUNT(*) AS total FROM ${t.jobs} WHERE ${where}`, params)]);
|
|
651
|
+
const where = listWhere(query);
|
|
652
|
+
const [rows, count] = await Promise.all([selectRows(conn, `SELECT * FROM ${t.jobs} WHERE ${where.sql} ORDER BY updated_at DESC, id DESC LIMIT ? OFFSET ?`, [
|
|
653
|
+
...where.params,
|
|
654
|
+
query.limit,
|
|
655
|
+
query.offset
|
|
656
|
+
]), selectOne(conn, `SELECT COUNT(*) AS total FROM ${t.jobs} WHERE ${where.sql}`, where.params)]);
|
|
582
657
|
return {
|
|
583
658
|
jobs: rows.map(toJob),
|
|
584
659
|
total: Number(count?.total ?? 0)
|
|
585
660
|
};
|
|
586
661
|
},
|
|
662
|
+
listJobGroups: async (query) => inSpaces(query.spaceIds) ? listJobGroupsOf(await db(), t.jobs, query) : {
|
|
663
|
+
groups: [],
|
|
664
|
+
total: 0,
|
|
665
|
+
jobs: 0
|
|
666
|
+
},
|
|
587
667
|
countDue: async ({ spaces, memoryMb } = {}) => {
|
|
588
668
|
const conn = await db();
|
|
589
669
|
const where = claimable(await clock.now(), spaces, memoryMb);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JobGroup, JobQuery } from '../types';
|
|
2
|
+
import { Pool } from 'mysql2/promise';
|
|
3
|
+
/** The jobs a list names (`listJobs`, `listJobGroups`): the clause and its parameters. */
|
|
4
|
+
export declare const listWhere: ({ spaceIds, name, status, kind }: JobQuery) => {
|
|
5
|
+
sql: string;
|
|
6
|
+
params: unknown[];
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* `JobQueue.listJobGroups` over the jobs table: a group per space, work and status, the one of the most recently
|
|
10
|
+
* touched job first. Each group's latest job — by `updated_at`, then `id`, as `listJobs` orders them — is read off one
|
|
11
|
+
* MAX of the two written as one string: MySQL 5.7 has no window functions. A query naming no space is answered empty
|
|
12
|
+
* by the caller (`IN ()` is not SQL).
|
|
13
|
+
*/
|
|
14
|
+
export declare const listJobGroupsOf: (conn: Pool, table: string, query: JobQuery) => Promise<{
|
|
15
|
+
groups: JobGroup[];
|
|
16
|
+
total: number;
|
|
17
|
+
jobs: number;
|
|
18
|
+
}>;
|
package/dist/mysql/rows.d.ts
CHANGED
|
@@ -34,6 +34,11 @@ export type JobRow = {
|
|
|
34
34
|
needs_memory_mb: Numeric | null;
|
|
35
35
|
near_memory_limit: Numeric;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* A job's row as a list reads it: every column but what a job of the functions saved (`state`, up to megabytes, and no
|
|
39
|
+
* list shows it) — read as NULL, so `toJob` reads it as none.
|
|
40
|
+
*/
|
|
41
|
+
export declare const LISTED_JOB_COLUMNS: string;
|
|
37
42
|
export type ScheduleRow = {
|
|
38
43
|
space_id: Numeric;
|
|
39
44
|
action_id: string;
|
package/dist/sqlite/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as stateOf, t as documentOf } from "../chunks/queueDocument-
|
|
2
|
-
import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-
|
|
1
|
+
import { n as stateOf, t as documentOf } from "../chunks/queueDocument-wwfFHQvw.mjs";
|
|
2
|
+
import { a as emptyState, i as changedBy, o as queueOver, r as applyRule, s as queueRules } from "../chunks/queueRules-DCW5x5as.mjs";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { DatabaseSync } from "node:sqlite";
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type { ActionLookupsConfig, ConnectorLookupsConfig, EngineConfig, EngineOptions, EngineServerConfig, SSRActionConfig, ActionJobsConfig } from './config';
|
|
2
|
-
export type { ActionSchedule, ActionScheduleInput, JobClaimMemory, JobQuery, JobQueue, JobFlowMinute, JobQueueSummary, JobSettlement, JobsDropped, JobsNeedingMemory, JobsToDrop, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
|
|
2
|
+
export type { ActionSchedule, ActionScheduleInput, JobClaimMemory, JobQuery, JobQueue, JobFlowMinute, JobGroup, JobQueueSummary, JobSettlement, JobsDropped, JobsNeedingMemory, JobsToDrop, JobSpaces, JobStop, JobTake, JobWake, JobWrite, WaitingJobs } from './jobs';
|
package/dist/types/jobs.d.ts
CHANGED
|
@@ -146,6 +146,20 @@ export type JobQuery = {
|
|
|
146
146
|
limit: number;
|
|
147
147
|
offset: number;
|
|
148
148
|
};
|
|
149
|
+
/**
|
|
150
|
+
* Jobs that say the same thing — one space's runs of one work (`target.kind` and `target.name`) in one status: what
|
|
151
|
+
* `JobQueue.listJobGroups` answers as one row, and exactly what `cancelWaiting` drops at once when narrowed to them.
|
|
152
|
+
*/
|
|
153
|
+
export type JobGroup = {
|
|
154
|
+
/** The most recently touched of them, as `listJobs` reads it, without what a job of the functions saved (`state`). */
|
|
155
|
+
latest: Omit<Job, 'state'>;
|
|
156
|
+
/** How many jobs the group holds, `latest` among them. */
|
|
157
|
+
count: number;
|
|
158
|
+
/** The earliest `dueAt` among them. */
|
|
159
|
+
firstDueAt: number;
|
|
160
|
+
/** The latest `dueAt` among them. */
|
|
161
|
+
lastDueAt: number;
|
|
162
|
+
};
|
|
149
163
|
/**
|
|
150
164
|
* Which jobs an operator drops at once (`JobQueue.cancelWaiting`): everything of these spaces that has not started —
|
|
151
165
|
* waiting to run or set aside — narrowed like a list of them is.
|
|
@@ -281,6 +295,17 @@ export type JobQueue = {
|
|
|
281
295
|
jobs: Job[];
|
|
282
296
|
total: number;
|
|
283
297
|
}>;
|
|
298
|
+
/**
|
|
299
|
+
* The jobs `listJobs` would list, a {@link JobGroup} per space, work and status — the group of the most recently
|
|
300
|
+
* touched job first — paged by groups, `total` counting them and `jobs` the jobs they hold, every page's. What a queue
|
|
301
|
+
* reads as a list a person scans: a schedule whose every fire was set aside is one row saying how many, not a page of
|
|
302
|
+
* the same line, every page alike.
|
|
303
|
+
*/
|
|
304
|
+
listJobGroups: (query: JobQuery) => Promise<{
|
|
305
|
+
groups: JobGroup[];
|
|
306
|
+
total: number;
|
|
307
|
+
jobs: number;
|
|
308
|
+
}>;
|
|
284
309
|
/**
|
|
285
310
|
* Jobs of EVERY space in these statuses — an operator's view, never a space's own (`listJobs` is): the longest due first
|
|
286
311
|
* (`due`), or the latest written first (`latest`). What a monitoring screen lists of what waits, runs and just ended.
|
package/dist/worker/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { handleRealtimePublish, handleRealtimeSocket, handleRealtimeSubscribe, realtimeModuleFor } from "../realtime/index.mjs";
|
|
2
2
|
import { a as createActionResolver, i as readRenderAsk, n as RENDER_PATH, t as createRemoteRenderResolver } from "../chunks/remote-DZSzOO01.mjs";
|
|
3
|
-
import { F as readKeptCall, P as keepCall, R as writeConnectorRecord, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule } from "../chunks/module-
|
|
3
|
+
import { F as readKeptCall, P as keepCall, R as writeConnectorRecord, S as ACTIONS_FLEET_STORES, h as precheckRun, t as createActionsModule } from "../chunks/module-BejdMWyt.mjs";
|
|
4
4
|
import { a as triggerParams, i as findTriggerNode, t as ActionRunError } from "../chunks/errors-bCBfIe7c.mjs";
|
|
5
|
-
import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-
|
|
6
|
-
import { t as isFunctionsDefinition } from "../chunks/load-
|
|
5
|
+
import { r as createConnectorResolver, t as describeCatalog } from "../chunks/taskCatalog-Crx-1ixP.mjs";
|
|
6
|
+
import { t as isFunctionsDefinition } from "../chunks/load-Dhjk46sd.mjs";
|
|
7
7
|
import { privateOriginsOf } from "@plitzi/sdk-kernel/outbound";
|
|
8
8
|
import { isConnectorManifestDraft, validateConnectorManifest } from "@plitzi/sdk-shared/connectors";
|
|
9
9
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-actions",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.11",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"description": "The actions engine: server actions, a space's functions and runtimes as the platform holds them, the connectors, realtime, jobs, and the stock queues and stores. What a worker runs; what a page server is handed.",
|
|
6
6
|
"files": [
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"build:prod": "vite build"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@plitzi/sdk-kernel": "0.39.
|
|
41
|
-
"@plitzi/sdk-shared": "0.39.
|
|
40
|
+
"@plitzi/sdk-kernel": "0.39.11",
|
|
41
|
+
"@plitzi/sdk-shared": "0.39.11",
|
|
42
42
|
"nodemailer": "^10.6.0",
|
|
43
43
|
"ws": "^8.23.0"
|
|
44
44
|
},
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@plitzi/sdk-runtime": "0.39.
|
|
62
|
+
"@plitzi/sdk-runtime": "0.39.11",
|
|
63
63
|
"@types/node": "^26.6.6",
|
|
64
64
|
"@types/nodemailer": "^8.0.2",
|
|
65
65
|
"@types/ws": "^8.18.2",
|