velocious 1.0.519 → 1.0.520
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/README.md +34 -0
- package/build/background-jobs/json-socket.js +12 -0
- package/build/background-jobs/main.js +78 -23
- package/build/background-jobs/store.js +87 -5
- package/build/background-jobs/types.js +4 -2
- package/build/background-jobs/worker.js +113 -23
- package/build/configuration-types.js +11 -2
- package/build/configuration.js +1 -1
- package/build/environment-handlers/node/cli/commands/generate/base-models.js +1 -1
- package/build/jobs/prune-terminal-background-jobs.js +67 -0
- package/build/src/background-jobs/json-socket.d.ts +12 -0
- package/build/src/background-jobs/json-socket.d.ts.map +1 -1
- package/build/src/background-jobs/json-socket.js +13 -1
- package/build/src/background-jobs/main.d.ts +18 -9
- package/build/src/background-jobs/main.d.ts.map +1 -1
- package/build/src/background-jobs/main.js +73 -26
- package/build/src/background-jobs/store.d.ts +16 -0
- package/build/src/background-jobs/store.d.ts.map +1 -1
- package/build/src/background-jobs/store.js +75 -5
- package/build/src/background-jobs/types.d.ts +14 -3
- package/build/src/background-jobs/types.d.ts.map +1 -1
- package/build/src/background-jobs/types.js +5 -3
- package/build/src/background-jobs/worker.d.ts +55 -7
- package/build/src/background-jobs/worker.d.ts.map +1 -1
- package/build/src/background-jobs/worker.js +108 -22
- package/build/src/configuration-types.d.ts +35 -4
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +12 -3
- package/build/src/configuration.d.ts +4 -2
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +2 -2
- package/build/src/environment-handlers/node/cli/commands/generate/base-models.js +2 -2
- package/build/src/jobs/prune-terminal-background-jobs.d.ts +23 -0
- package/build/src/jobs/prune-terminal-background-jobs.d.ts.map +1 -0
- package/build/src/jobs/prune-terminal-background-jobs.js +61 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/background-jobs/json-socket.js +12 -0
- package/src/background-jobs/main.js +78 -23
- package/src/background-jobs/store.js +87 -5
- package/src/background-jobs/types.js +4 -2
- package/src/background-jobs/worker.js +113 -23
- package/src/configuration-types.js +11 -2
- package/src/configuration.js +1 -1
- package/src/environment-handlers/node/cli/commands/generate/base-models.js +1 -1
- package/src/jobs/prune-terminal-background-jobs.js +67 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import BackgroundJobsStore from "../background-jobs/store.js"
|
|
4
|
+
import Configuration from "../configuration.js"
|
|
5
|
+
import VelociousJob from "../background-jobs/job.js"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Built-in job that prunes terminal `background_jobs` rows past their retention
|
|
9
|
+
* window so the table does not grow unbounded. The main process registers this
|
|
10
|
+
* on the normal background-jobs scheduler when `backgroundJobs.retention` is
|
|
11
|
+
* enabled, so it runs as an ordinary scheduled/queued job — visible in the job
|
|
12
|
+
* tables and dispatched to a worker — rather than a hidden in-process timer.
|
|
13
|
+
* @augments {VelociousJob<[]>}
|
|
14
|
+
*/
|
|
15
|
+
export default class PruneTerminalBackgroundJobsJob extends VelociousJob {
|
|
16
|
+
/**
|
|
17
|
+
* Reserved job name that an application job cannot shadow. The registry loads
|
|
18
|
+
* app `src/jobs` first and skips duplicate built-in names, so if this used the
|
|
19
|
+
* default class-name identity an app class named `PruneTerminalBackgroundJobsJob`
|
|
20
|
+
* would be dispatched instead. A `:`-namespaced name can never collide with a
|
|
21
|
+
* default (class-name) identity, since class names cannot contain `:`.
|
|
22
|
+
* @returns {string} - Reserved job name.
|
|
23
|
+
*/
|
|
24
|
+
static jobName() {
|
|
25
|
+
return "velocious:prune-terminal-background-jobs"
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Builds the scheduler configuration for this job from a resolved retention
|
|
30
|
+
* config, or returns `null` when retention is fully disabled (nothing to
|
|
31
|
+
* prune, so nothing to schedule). `maxConcurrency: 1` keeps runs from
|
|
32
|
+
* overlapping, and `deduplicateWhileQueued` stops the interval scheduler from
|
|
33
|
+
* piling up redundant queued rows when a prune is slow or no worker is free.
|
|
34
|
+
* @param {import("../configuration-types.js").ResolvedBackgroundJobsRetentionConfiguration} retention - Resolved retention config.
|
|
35
|
+
* @returns {import("../configuration-types.js").ScheduledBackgroundJobConfiguration | null} - Scheduler config for the prune job, or null when retention is disabled.
|
|
36
|
+
*/
|
|
37
|
+
static scheduleConfiguration(retention) {
|
|
38
|
+
const prunesCompleted = typeof retention.completedTtlMs === "number" && retention.completedTtlMs > 0
|
|
39
|
+
const prunesFailed = typeof retention.failedTtlMs === "number" && retention.failedTtlMs > 0
|
|
40
|
+
|
|
41
|
+
if (!prunesCompleted && !prunesFailed) {
|
|
42
|
+
return null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
class: this,
|
|
47
|
+
every: retention.sweepIntervalMs,
|
|
48
|
+
options: {concurrencyKey: "velocious-prune-terminal-background-jobs", maxConcurrency: 1, deduplicateWhileQueued: true}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Prunes terminal job rows past their retention window.
|
|
54
|
+
* @returns {Promise<void>}
|
|
55
|
+
*/
|
|
56
|
+
async perform() {
|
|
57
|
+
const configuration = Configuration.current()
|
|
58
|
+
const config = configuration.getBackgroundJobsConfig()
|
|
59
|
+
const store = new BackgroundJobsStore({configuration, databaseIdentifier: config.databaseIdentifier})
|
|
60
|
+
|
|
61
|
+
await store.pruneTerminalJobs({
|
|
62
|
+
completedTtlMs: config.retention.completedTtlMs,
|
|
63
|
+
failedTtlMs: config.retention.failedTtlMs,
|
|
64
|
+
batchSize: config.retention.batchSize
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
}
|