@soffits/dsh-cron-jobs 0.7.1 → 0.9.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/README.md +80 -7
- package/bin/dsh-cron-event.js +101 -0
- package/client.js +32 -5
- package/index.js +28 -1
- package/package.json +7 -3
- package/src/config.js +18 -1
- package/src/controller.js +341 -22
- package/src/deliver.js +15 -3
- package/src/events.js +302 -0
- package/src/history.js +28 -8
- package/src/job.js +216 -81
- package/src/prompt.js +55 -9
- package/src/session.js +2 -2
- package/src/spool.js +176 -0
- package/src/store.js +17 -1
- package/src/watchers.js +374 -0
- package/tools.js +59 -4
package/src/events.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Events: named hints from outside DSH (a CLI, a hook, a watcher) that start
|
|
3
|
+
* the jobs subscribed to their channel. An event only says "look now"; the
|
|
4
|
+
* job reads the truth from its source, so a lost or forged event costs at
|
|
5
|
+
* most one missed or wasted run (the job's schedule is the safety net).
|
|
6
|
+
*
|
|
7
|
+
* - Channels are dot-separated names such as `mail.sakina` or `dsh.started`.
|
|
8
|
+
* - A job's `on` lists channel patterns; `*` matches one or more characters
|
|
9
|
+
* of any kind, dots included (`mail.*` matches `mail.icloud.inbox`).
|
|
10
|
+
* - An event may carry a dedupe key: a second event with the same channel and
|
|
11
|
+
* key within an hour is dropped.
|
|
12
|
+
*/
|
|
13
|
+
import { homedir } from 'node:os'
|
|
14
|
+
import { join } from 'node:path'
|
|
15
|
+
|
|
16
|
+
/** Longest channel name or pattern. */
|
|
17
|
+
export const MAX_CHANNEL_LENGTH = 200
|
|
18
|
+
/** Characters of an event's text, and of its data as JSON, that are kept. */
|
|
19
|
+
export const MAX_EVENT_BYTES = 16 * 1024
|
|
20
|
+
/** How long a dedupe key is remembered. */
|
|
21
|
+
export const DEDUPE_MS = 3600 * 1000
|
|
22
|
+
|
|
23
|
+
const SEGMENT = '[A-Za-z0-9_:-]+'
|
|
24
|
+
const CHANNEL = new RegExp(`^${SEGMENT}(\\.${SEGMENT})*$`)
|
|
25
|
+
const PATTERN = /^[A-Za-z0-9_:.*-]+$/
|
|
26
|
+
|
|
27
|
+
/** A request to emit or subscribe that cannot be carried out. */
|
|
28
|
+
export class EventInputError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(message)
|
|
31
|
+
this.name = 'EventInputError'
|
|
32
|
+
this.code = 'invalid_event'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The event inbox under the DSH home. */
|
|
37
|
+
export function defaultEventDir(env = process.env) {
|
|
38
|
+
return env.DSH_CRON_EVENTS_DIR || join(env.DSH_HOME || join(homedir(), '.dsh'), 'cron-jobs', 'events')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** State directory given to each watcher. */
|
|
42
|
+
export function defaultWatcherStateRoot(env = process.env) {
|
|
43
|
+
return join(env.DSH_HOME || join(homedir(), '.dsh'), 'cron-jobs', 'watchers')
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function isChannel(value) {
|
|
47
|
+
return typeof value === 'string' && value.length <= MAX_CHANNEL_LENGTH && CHANNEL.test(value)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isPattern(value) {
|
|
51
|
+
return typeof value === 'string' && value.length <= MAX_CHANNEL_LENGTH && PATTERN.test(value)
|
|
52
|
+
&& !value.startsWith('.') && !value.endsWith('.') && !value.includes('..')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Check and clean a list of channel patterns.
|
|
57
|
+
* @returns {string[]} The patterns, trimmed and without duplicates.
|
|
58
|
+
* @throws {EventInputError}
|
|
59
|
+
*/
|
|
60
|
+
export function checkPatterns(list) {
|
|
61
|
+
if (!Array.isArray(list)) throw new EventInputError('on must be a list of channel patterns')
|
|
62
|
+
const out = []
|
|
63
|
+
for (const raw of list) {
|
|
64
|
+
const value = typeof raw === 'string' ? raw.trim() : raw
|
|
65
|
+
if (!isPattern(value)) throw new EventInputError(`${JSON.stringify(raw)} is not a channel pattern: dot-separated names of letters, digits, _ : -, with * for any characters`)
|
|
66
|
+
if (!out.includes(value)) out.push(value)
|
|
67
|
+
}
|
|
68
|
+
return out
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Whether a channel matches one pattern. */
|
|
72
|
+
export function channelMatches(pattern, channel) {
|
|
73
|
+
if (!pattern.includes('*')) return pattern === channel
|
|
74
|
+
const parts = pattern.split('*').map(part => part.replace(/[.\\^$+?()[\]{}|-]/g, '\\$&'))
|
|
75
|
+
return new RegExp(`^${parts.join('.+')}$`).test(channel)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Whether a channel matches any of a job's patterns. */
|
|
79
|
+
export function subscribed(patterns, channel) {
|
|
80
|
+
return Array.isArray(patterns) && patterns.some(pattern => channelMatches(pattern, channel))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* An event as jobs see it. Data that is not JSON-safe, too large data and
|
|
85
|
+
* long text are cut down rather than refused, since a watcher's line should
|
|
86
|
+
* still wake its job.
|
|
87
|
+
* @param {{ channel: string, data?: any, text?: string, key?: string, source?: string, at?: string }} input
|
|
88
|
+
* @param {() => Date} [now]
|
|
89
|
+
* @throws {EventInputError} for a missing or malformed channel.
|
|
90
|
+
*/
|
|
91
|
+
export function normalizeEvent(input, now = () => new Date()) {
|
|
92
|
+
if (input === null || typeof input !== 'object') throw new EventInputError('an event must be an object')
|
|
93
|
+
const channel = typeof input.channel === 'string' ? input.channel.trim() : input.channel
|
|
94
|
+
if (!isChannel(channel)) throw new EventInputError(`${JSON.stringify(input.channel)} is not a channel name: dot-separated names of letters, digits, _ : -`)
|
|
95
|
+
const event = { channel, at: validTime(input.at) ?? now().toISOString() }
|
|
96
|
+
if (typeof input.key === 'string' && input.key.trim() !== '') event.key = input.key.trim().slice(0, 200)
|
|
97
|
+
if (typeof input.source === 'string' && input.source.trim() !== '') event.source = input.source.trim().slice(0, 200)
|
|
98
|
+
if (input.data !== undefined) {
|
|
99
|
+
let json
|
|
100
|
+
try {
|
|
101
|
+
json = JSON.stringify(input.data)
|
|
102
|
+
} catch {
|
|
103
|
+
json = undefined
|
|
104
|
+
}
|
|
105
|
+
if (json === undefined) event.text = String(input.data).slice(0, MAX_EVENT_BYTES)
|
|
106
|
+
else if (json.length <= MAX_EVENT_BYTES) event.data = JSON.parse(json)
|
|
107
|
+
else event.text = `${json.slice(0, MAX_EVENT_BYTES)}… [data cut at ${MAX_EVENT_BYTES} characters]`
|
|
108
|
+
}
|
|
109
|
+
if (typeof input.text === 'string' && input.text.trim() !== '' && event.text === undefined) {
|
|
110
|
+
event.text = input.text.length > MAX_EVENT_BYTES ? `${input.text.slice(0, MAX_EVENT_BYTES)}… [text cut]` : input.text
|
|
111
|
+
}
|
|
112
|
+
return event
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function validTime(value) {
|
|
116
|
+
if (typeof value !== 'string') return undefined
|
|
117
|
+
const time = Date.parse(value)
|
|
118
|
+
return Number.isFinite(time) ? new Date(time).toISOString() : undefined
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Remembers dedupe keys for an hour. */
|
|
122
|
+
export class Deduper {
|
|
123
|
+
constructor({ windowMs = DEDUPE_MS, now = () => Date.now() } = {}) {
|
|
124
|
+
this.windowMs = windowMs
|
|
125
|
+
this.now = now
|
|
126
|
+
this.seen = new Map()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** True when this channel and key were seen within the window; records it otherwise. */
|
|
130
|
+
seenBefore(event) {
|
|
131
|
+
if (event.key === undefined) return false
|
|
132
|
+
const now = this.now()
|
|
133
|
+
for (const [key, expires] of this.seen) {
|
|
134
|
+
if (expires > now) break
|
|
135
|
+
this.seen.delete(key)
|
|
136
|
+
}
|
|
137
|
+
const id = `${event.channel}\u0000${event.key}`
|
|
138
|
+
const expires = this.seen.get(id)
|
|
139
|
+
if (expires !== undefined && expires > now) return true
|
|
140
|
+
this.seen.delete(id)
|
|
141
|
+
this.seen.set(id, now + this.windowMs)
|
|
142
|
+
return false
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Default batching of events per job. */
|
|
147
|
+
export const DEFAULT_COALESCE_SECONDS = 30
|
|
148
|
+
export const DEFAULT_MAX_RUNS_PER_HOUR = 6
|
|
149
|
+
/** Events kept in one batch; older ones are counted as dropped. */
|
|
150
|
+
export const MAX_BATCH_EVENTS = 50
|
|
151
|
+
|
|
152
|
+
const HOUR_MS = 3600 * 1000
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Gathers one job's events into batches and starts a run per batch:
|
|
156
|
+
*
|
|
157
|
+
* - The first event of a batch opens a window (`coalesceMs`); everything that
|
|
158
|
+
* arrives in it joins the batch, and the batch runs when it closes.
|
|
159
|
+
* - A job that is still running when the window closes runs again as soon as
|
|
160
|
+
* it ends, with every event gathered meanwhile (one follow-up run).
|
|
161
|
+
* - At most `maxRunsPerHour` event runs start in any hour; past that, events
|
|
162
|
+
* wait in the batch until the oldest of those runs is an hour old.
|
|
163
|
+
*
|
|
164
|
+
* Each event comes with a `release` callback, called once the event's run
|
|
165
|
+
* has started (or the event is discarded), so a spool file is only removed
|
|
166
|
+
* when nothing can lose it any more.
|
|
167
|
+
*/
|
|
168
|
+
export class EventBatcher {
|
|
169
|
+
/**
|
|
170
|
+
* @param {object} options
|
|
171
|
+
* @param {(batch: { events: object[], dropped: number }) => void} options.start - Starts a run with the batch.
|
|
172
|
+
* @param {() => boolean} options.busy - Whether the job is running now.
|
|
173
|
+
* @param {number} [options.coalesceMs]
|
|
174
|
+
* @param {number} [options.maxRunsPerHour] - 0 means no cap.
|
|
175
|
+
* @param {() => number} [options.now]
|
|
176
|
+
* @param {{ set: typeof setTimeout, clear: typeof clearTimeout }} [options.timers]
|
|
177
|
+
*/
|
|
178
|
+
constructor({ start, busy, coalesceMs = DEFAULT_COALESCE_SECONDS * 1000, maxRunsPerHour = DEFAULT_MAX_RUNS_PER_HOUR, now = () => Date.now(), timers = { set: setTimeout, clear: clearTimeout } }) {
|
|
179
|
+
this.startRun = start
|
|
180
|
+
this.busy = busy
|
|
181
|
+
this.coalesceMs = coalesceMs
|
|
182
|
+
this.maxRunsPerHour = maxRunsPerHour
|
|
183
|
+
this.now = now
|
|
184
|
+
this.timers = timers
|
|
185
|
+
this.pending = []
|
|
186
|
+
this.releases = []
|
|
187
|
+
this.dropped = 0
|
|
188
|
+
this.openedAt = undefined
|
|
189
|
+
this.timer = undefined
|
|
190
|
+
this.recent = []
|
|
191
|
+
this.stopped = false
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Number of events waiting. */
|
|
195
|
+
get size() {
|
|
196
|
+
return this.pending.length
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** When the waiting batch is due to run, or undefined. */
|
|
200
|
+
get dueAt() {
|
|
201
|
+
return this.pending.length === 0 ? undefined : this.due()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
add(event, release = () => {}) {
|
|
205
|
+
if (this.stopped) return
|
|
206
|
+
if (this.pending.length === 0) this.openedAt = this.now()
|
|
207
|
+
this.pending.push(event)
|
|
208
|
+
this.releases.push(release)
|
|
209
|
+
if (this.pending.length > MAX_BATCH_EVENTS) {
|
|
210
|
+
this.pending.shift()
|
|
211
|
+
this.dropped++
|
|
212
|
+
}
|
|
213
|
+
this.arm()
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
due() {
|
|
217
|
+
let at = this.openedAt + this.coalesceMs
|
|
218
|
+
if (this.maxRunsPerHour > 0) {
|
|
219
|
+
const now = this.now()
|
|
220
|
+
this.recent = this.recent.filter(time => now - time < HOUR_MS)
|
|
221
|
+
if (this.recent.length >= this.maxRunsPerHour) at = Math.max(at, this.recent[this.recent.length - this.maxRunsPerHour] + HOUR_MS)
|
|
222
|
+
}
|
|
223
|
+
return at
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
arm() {
|
|
227
|
+
if (this.stopped || this.timer !== undefined || this.pending.length === 0) return
|
|
228
|
+
const delay = Math.max(0, this.due() - this.now())
|
|
229
|
+
this.timer = this.timers.set(() => {
|
|
230
|
+
this.timer = undefined
|
|
231
|
+
this.flush()
|
|
232
|
+
}, delay)
|
|
233
|
+
this.timer?.unref?.()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Run the batch if it is due and the job is idle; otherwise wait. */
|
|
237
|
+
flush() {
|
|
238
|
+
if (this.stopped || this.pending.length === 0) return
|
|
239
|
+
if (this.due() > this.now()) return this.arm()
|
|
240
|
+
// Running: idle() starts the follow-up run when the current one ends.
|
|
241
|
+
if (this.busy()) return
|
|
242
|
+
const batch = { events: this.pending, dropped: this.dropped }
|
|
243
|
+
const releases = this.releases
|
|
244
|
+
this.pending = []
|
|
245
|
+
this.releases = []
|
|
246
|
+
this.dropped = 0
|
|
247
|
+
this.openedAt = undefined
|
|
248
|
+
this.recent.push(this.now())
|
|
249
|
+
this.startRun(batch)
|
|
250
|
+
for (const release of releases) release()
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/** The job's run ended: start a waiting batch whose window has closed. */
|
|
254
|
+
idle() {
|
|
255
|
+
if (this.timer === undefined) this.flush()
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Drop waiting events (job paused, ended or deleted); they are released. */
|
|
259
|
+
discard() {
|
|
260
|
+
if (this.timer !== undefined) this.timers.clear(this.timer)
|
|
261
|
+
this.timer = undefined
|
|
262
|
+
const releases = this.releases
|
|
263
|
+
this.pending = []
|
|
264
|
+
this.releases = []
|
|
265
|
+
this.dropped = 0
|
|
266
|
+
this.openedAt = undefined
|
|
267
|
+
for (const release of releases) release()
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Stop without releasing: unreleased spool events are read again at the next start. */
|
|
271
|
+
stop() {
|
|
272
|
+
this.stopped = true
|
|
273
|
+
if (this.timer !== undefined) this.timers.clear(this.timer)
|
|
274
|
+
this.timer = undefined
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Bytes of events placed in an agent prompt. */
|
|
279
|
+
export const MAX_PROMPT_EVENT_BYTES = 32 * 1024
|
|
280
|
+
|
|
281
|
+
/** One line per event, as shown to a gate on stdin and to an agent. */
|
|
282
|
+
export function eventLines(batch, limit = Infinity) {
|
|
283
|
+
const lines = batch.events.map(event => JSON.stringify(event))
|
|
284
|
+
let omitted = batch.dropped
|
|
285
|
+
let size = lines.reduce((sum, line) => sum + Buffer.byteLength(line) + 1, 0)
|
|
286
|
+
while (size > limit && lines.length > 1) {
|
|
287
|
+
size -= Buffer.byteLength(lines.shift()) + 1
|
|
288
|
+
omitted++
|
|
289
|
+
}
|
|
290
|
+
return { lines, omitted }
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** What a command gets on stdin for an event run. */
|
|
294
|
+
export function eventInput(batch) {
|
|
295
|
+
return `${JSON.stringify({ trigger: 'event', events: batch.events, dropped: batch.dropped })}\n`
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** Short summary of a batch for the run history and run log. */
|
|
299
|
+
export function batchSummary(batch) {
|
|
300
|
+
const channels = [...new Set(batch.events.map(event => event.channel))]
|
|
301
|
+
return { count: batch.events.length + batch.dropped, channels: channels.slice(0, 20) }
|
|
302
|
+
}
|
package/src/history.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
2
|
import { z } from 'zod'
|
|
3
|
-
import { storedJobSchema } from './store.js'
|
|
3
|
+
import { storedJobSchema, storedWatcherSchema } from './store.js'
|
|
4
4
|
|
|
5
5
|
/** Default number of runs kept per job. */
|
|
6
6
|
export const DEFAULT_HISTORY_RECORDS = 50
|
|
@@ -10,7 +10,9 @@ export const HISTORY_TAIL_CHARS = 1000
|
|
|
10
10
|
|
|
11
11
|
const runSchema = z.object({
|
|
12
12
|
id: z.string(),
|
|
13
|
-
trigger: z.enum(['schedule', 'manual']),
|
|
13
|
+
trigger: z.enum(['schedule', 'manual', 'event']),
|
|
14
|
+
// Events that started an event run: how many, and on which channels.
|
|
15
|
+
events: z.object({ count: z.number(), channels: z.array(z.string()) }).optional(),
|
|
14
16
|
startedAt: z.string(),
|
|
15
17
|
// 'running' while the command runs; afterwards the run's outcome:
|
|
16
18
|
// done, idle, woke, failed, wake-failed, or interrupted (DSH stopped mid-run).
|
|
@@ -30,6 +32,23 @@ const runSchema = z.object({
|
|
|
30
32
|
reuseNote: z.string().optional(),
|
|
31
33
|
// The prompt went to the job's target session (an existing session, or the one a new_once job opened).
|
|
32
34
|
targeted: z.boolean().optional(),
|
|
35
|
+
// The turn the woken prompt started: pending until it ends, then ended, or
|
|
36
|
+
// cut-off when DSH disposed it (a restart or reload) before it finished.
|
|
37
|
+
turn: z.object({
|
|
38
|
+
status: z.enum(['pending', 'ended', 'cut-off']),
|
|
39
|
+
messageId: z.string(),
|
|
40
|
+
reason: z.string().optional(),
|
|
41
|
+
}).optional(),
|
|
42
|
+
// A cut-off run's one rerun: pending until DSH is back, then started (see
|
|
43
|
+
// runId) or skipped (see note).
|
|
44
|
+
rerun: z.object({
|
|
45
|
+
status: z.enum(['pending', 'started', 'skipped']),
|
|
46
|
+
at: z.string().optional(),
|
|
47
|
+
runId: z.string().optional(),
|
|
48
|
+
note: z.string().optional(),
|
|
49
|
+
}).optional(),
|
|
50
|
+
// This run reruns the cut-off run with this id.
|
|
51
|
+
rerunOf: z.string().optional(),
|
|
33
52
|
// Auto-archive of the woken session: pending until its turn ends, then
|
|
34
53
|
// archived, kept (see archiveNote), or superseded (a later run reused it).
|
|
35
54
|
archive: z.enum(['pending', 'archived', 'kept', 'superseded']).optional(),
|
|
@@ -68,14 +87,14 @@ const jobStateSchema = z.object({
|
|
|
68
87
|
* The `single` layout keeps everything in one unit, so keys need no
|
|
69
88
|
* escaping; a record that fails validation is backed up and skipped instead
|
|
70
89
|
* of blocking the whole domain. A table missing from an older file loads as
|
|
71
|
-
* empty, so adding `tasks` needed no version change.
|
|
90
|
+
* empty, so adding `tasks` and `watchers` needed no version change.
|
|
72
91
|
*/
|
|
73
92
|
export const historyDomain = Object.freeze({
|
|
74
93
|
name: 'cron_jobs',
|
|
75
94
|
version: 1,
|
|
76
95
|
layout: 'single',
|
|
77
96
|
invalidRecords: 'backup-and-skip',
|
|
78
|
-
tables: { jobs: { valueSchema: jobStateSchema }, tasks: { valueSchema: storedJobSchema } },
|
|
97
|
+
tables: { jobs: { valueSchema: jobStateSchema }, tasks: { valueSchema: storedJobSchema }, watchers: { valueSchema: storedWatcherSchema } },
|
|
79
98
|
})
|
|
80
99
|
|
|
81
100
|
/** @typedef {z.infer<typeof runSchema>} Run */
|
|
@@ -99,9 +118,10 @@ export class HistoryStore {
|
|
|
99
118
|
* @param {boolean} [options.durable] - Whether the table survives a restart.
|
|
100
119
|
* @param {object} [options.tasks] - Table of stored jobs, see store.js; in memory when omitted.
|
|
101
120
|
*/
|
|
102
|
-
constructor({ table, limit = DEFAULT_HISTORY_RECORDS, logger, close = async () => {}, durable = false, tasks = memoryTable() }) {
|
|
121
|
+
constructor({ table, limit = DEFAULT_HISTORY_RECORDS, logger, close = async () => {}, durable = false, tasks = memoryTable(), watchers = memoryTable() }) {
|
|
103
122
|
this.table = table
|
|
104
123
|
this.tasks = tasks
|
|
124
|
+
this.watchers = watchers
|
|
105
125
|
this.limit = limit
|
|
106
126
|
this.logger = logger
|
|
107
127
|
this.closeTable = close
|
|
@@ -133,11 +153,11 @@ export class HistoryStore {
|
|
|
133
153
|
* Save a started run and drop the oldest ones beyond the limit.
|
|
134
154
|
* @returns {Promise<string>} The run id.
|
|
135
155
|
*/
|
|
136
|
-
async begin(name, { trigger, startedAt }) {
|
|
156
|
+
async begin(name, { trigger, startedAt, events, rerunOf }) {
|
|
137
157
|
const id = randomUUID()
|
|
138
158
|
await this.change(name, state => ({
|
|
139
159
|
...state,
|
|
140
|
-
runs: [...state.runs, { id, trigger, startedAt, status: 'running' }].slice(-this.limit),
|
|
160
|
+
runs: [...state.runs, { id, trigger, startedAt, status: 'running', ...(events ? { events } : {}), ...(rerunOf ? { rerunOf } : {}) }].slice(-this.limit),
|
|
141
161
|
}))
|
|
142
162
|
return id
|
|
143
163
|
}
|
|
@@ -248,7 +268,7 @@ export async function openHistory(storageDomain, { limit, logger, signal, retryM
|
|
|
248
268
|
try {
|
|
249
269
|
const domain = await storageDomain.open(historyDomain)
|
|
250
270
|
const store = new HistoryStore({
|
|
251
|
-
table: domain.table('jobs'), tasks: domain.table('tasks'), limit, logger, durable: true, close: () => domain.close(),
|
|
271
|
+
table: domain.table('jobs'), tasks: domain.table('tasks'), watchers: domain.table('watchers'), limit, logger, durable: true, close: () => domain.close(),
|
|
252
272
|
})
|
|
253
273
|
await store.markInterrupted()
|
|
254
274
|
return store
|