@soffits/dsh-cron-jobs 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/package.json +1 -1
- package/src/session.js +30 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soffits/dsh-cron-jobs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Scheduled jobs for DeepSeek Harness: shell commands and agent prompts on cron, RRULE or one-time schedules, a gate that wakes an agent only when there is something to do, result delivery through any plugin that can send messages, tools to manage jobs from a conversation, and a Cron tasks page in the Web GUI.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
package/src/session.js
CHANGED
|
@@ -167,9 +167,11 @@ export const ARCHIVE_ATTEMPTS = 60
|
|
|
167
167
|
*/
|
|
168
168
|
export async function archiveWhenIdle(ctx, sessionId, {
|
|
169
169
|
signal, isLatest = () => true, lock = fn => fn(), retryMs = ARCHIVE_RETRY_MS, attempts = ARCHIVE_ATTEMPTS,
|
|
170
|
+
serviceWaitMs = SERVICE_WAIT_MS,
|
|
170
171
|
} = {}) {
|
|
171
|
-
const controller = ctx
|
|
172
|
-
const registry = ctx
|
|
172
|
+
const controller = await hostService(ctx, 'sessionController', { signal, waitMs: serviceWaitMs })
|
|
173
|
+
const registry = await hostService(ctx, 'workspaceRegistry', { signal, waitMs: serviceWaitMs })
|
|
174
|
+
if (signal?.aborted) return { archive: 'pending' }
|
|
173
175
|
if (controller === undefined || registry === undefined) {
|
|
174
176
|
return { archive: 'kept', note: 'this host has no workspace archive' }
|
|
175
177
|
}
|
|
@@ -220,8 +222,11 @@ export const ANSWER_ATTEMPTS = 120
|
|
|
220
222
|
* @param {number} [options.attempts]
|
|
221
223
|
* @returns {Promise<{ pending: true } | { text: string, reason?: string } | { error: string }>}
|
|
222
224
|
*/
|
|
223
|
-
export async function waitForAnswer(ctx, sessionId, messageId, {
|
|
224
|
-
|
|
225
|
+
export async function waitForAnswer(ctx, sessionId, messageId, {
|
|
226
|
+
signal, retryMs = ANSWER_RETRY_MS, attempts = ANSWER_ATTEMPTS, serviceWaitMs = SERVICE_WAIT_MS,
|
|
227
|
+
}) {
|
|
228
|
+
const controller = await hostService(ctx, 'sessionController', { signal, waitMs: serviceWaitMs })
|
|
229
|
+
if (signal?.aborted) return { pending: true }
|
|
225
230
|
if (controller === undefined) return { error: 'this host cannot read sessions (no sessionController service)' }
|
|
226
231
|
for (let attempt = 1; ; attempt++) {
|
|
227
232
|
const resolved = await controller.resolveAgent(sessionId)
|
|
@@ -237,6 +242,27 @@ export async function waitForAnswer(ctx, sessionId, messageId, { signal, retryMs
|
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
|
|
245
|
+
/** How long a resumed delivery or archive waits for a Host service to appear. */
|
|
246
|
+
export const SERVICE_WAIT_MS = 120_000
|
|
247
|
+
const SERVICE_POLL_MS = 500
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Read a Host service, waiting up to `waitMs` for it to be provided. At DSH
|
|
251
|
+
* startup this plugin can start (and resume runs an earlier copy left
|
|
252
|
+
* pending) before the session services are registered; reading them once
|
|
253
|
+
* then failed a pending delivery for good (2026-11-13, "no sessionController
|
|
254
|
+
* service" right after a restart). Resolves undefined when the service never
|
|
255
|
+
* appears or the signal aborts.
|
|
256
|
+
*/
|
|
257
|
+
export async function hostService(ctx, name, { signal, waitMs = SERVICE_WAIT_MS, pollMs = SERVICE_POLL_MS } = {}) {
|
|
258
|
+
const deadline = Date.now() + waitMs
|
|
259
|
+
for (;;) {
|
|
260
|
+
const service = ctx.get(name)
|
|
261
|
+
if (service !== undefined || signal?.aborted || Date.now() >= deadline) return service
|
|
262
|
+
await sleep(Math.min(pollMs, Math.max(0, deadline - Date.now())), signal)
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
240
266
|
function sleep(ms, signal) {
|
|
241
267
|
return new Promise((resolve) => {
|
|
242
268
|
const timer = setTimeout(done, ms)
|