@storyshelf/app 0.10.0-next-03e33be → 0.10.0-next-ccff478
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/capture-setup.mjs +3 -0
- package/dist/capture-setup.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/jobs-setup.mjs +11 -2
- package/dist/jobs-setup.mjs.map +1 -1
- package/package.json +6 -6
package/dist/capture-setup.mjs
CHANGED
|
@@ -99,6 +99,9 @@ function forkedHandler(options, parts) {
|
|
|
99
99
|
function alerting(inner, retries, alert) {
|
|
100
100
|
return {
|
|
101
101
|
accepts: (job) => inner.accepts?.(job) !== false,
|
|
102
|
+
deadlineExceeded: async (job, seconds) => {
|
|
103
|
+
await inner.deadlineExceeded?.(job, seconds);
|
|
104
|
+
},
|
|
102
105
|
superseded: async (job) => await inner.superseded?.(job) === true,
|
|
103
106
|
run: async (job, context) => {
|
|
104
107
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capture-setup.mjs","names":[],"sources":["../src/capture-setup.ts"],"sourcesContent":["/**\n * Capture wiring (ADR 0006, decisions 4 to 6): where uploads queue their capture, and the handler\n * of `capture` jobs. Captures queue on the shared database queue. The handler runs them in this process, or in a forked child the parent pushes jobs\n * to (`testing.workerEntry`). The consumer that polls the queue and calls the handler is built\n * in `jobs-setup.ts`.\n */\nimport type { CaptureQueue } from \"@storyshelf/core/adapter/capture-queue\";\nimport type { CaptureRunner } from \"@storyshelf/core/adapter/capture-runner\";\nimport type { NotifierProvider } from \"@storyshelf/core/adapter/notifier\";\nimport {\n captureDispatchDeps,\n createCaptureHandler,\n DEFAULT_RETRIES,\n failCrashedCapture,\n isFinalAttempt,\n type BuildStatePublisher,\n type CaptureHandlerOptions,\n type ConsumerJob,\n type KindHandler,\n} from \"@storyshelf/core/capture\";\nimport { DEFAULT_SCRATCH_DIR } from \"@storyshelf/core/config\";\nimport type { ShelfConfig, ShelfOptions } from \"@storyshelf/core/config\";\nimport type { Logger } from \"@storyshelf/core/logger\";\nimport { currentTraceparent } from \"@storyshelf/observability\";\nimport { notifyCaptureFailed, notifyCaptureStuck } from \"./capture-alerts.ts\";\nimport { createForkedHandler, shouldForkCapture } from \"./capture-process.ts\";\nimport { credentialKeys } from \"./credential-keys.ts\";\nimport type { JobQueue } from \"./job-queue.ts\";\n\n/** The `capture` handler, with a way to stop a forked child once the consumer has drained. */\nexport interface CaptureHandler extends KindHandler {\n close?: () => Promise<void>;\n}\n\n/** What uploads and the consumer need of capture. */\nexport interface CaptureWiring {\n /** Where captures queue: the database queue, or null without `testing`. */\n queue: CaptureQueue | null;\n /** Queues a capture for a build; undefined without `testing`. */\n enqueueCapture: ((buildId: string, reqId?: string) => Promise<void>) | undefined;\n /** Runs `capture` jobs here; null without `testing`. */\n handler: CaptureHandler | null;\n}\n\n/** What a capture hands its results to. */\ninterface Delivery {\n notifiers: NotifierProvider[];\n buildState: BuildStatePublisher;\n /** The resolved public origin (ADR 0007): status links and targets that need a URL use it. */\n publicOrigin: () => Promise<string | undefined>;\n}\n\n/** Queue a build, continuing the active request trace when present. */\nfunction enqueuerFor(queue: CaptureQueue): (buildId: string, reqId?: string) => Promise<void> {\n return async (buildId, reqId) => {\n const traceparent = currentTraceparent();\n await queue.enqueue({ buildId, reqId, ...(traceparent ? { traceparent } : {}) });\n };\n}\n\n/**\n * Wire capture for `options`: `testing` always has a runner, so this instance consumes the\n * captures it queues. Shard jobs go back onto the same queue the capture came from.\n */\nexport function setupCapture(\n options: ShelfOptions,\n config: ShelfConfig,\n delivery: Delivery,\n logger: Logger,\n jobs: JobQueue,\n): CaptureWiring {\n const testing = options.testing;\n if (testing === undefined) {\n return { queue: null, enqueueCapture: undefined, handler: null };\n }\n const queue = jobs.view;\n const enqueueCapture = enqueuerFor(queue);\n const handlerOptions = captureHandlerOptions(options, config, delivery, logger, {\n runner: testing.runner,\n enqueue: async (job) => {\n await queue.enqueue(job);\n },\n });\n const retries = options.testing?.retries ?? DEFAULT_RETRIES;\n const dispatch = captureDispatchDeps(handlerOptions, retries);\n const failed = async (job: ConsumerJob, error: string): Promise<void> => {\n await failCrashedCapture(dispatch, job, error);\n await notifyCaptureFailed(options, config, logger, job.buildId, delivery.publicOrigin);\n };\n jobs.exhausted.capture = failed;\n jobs.abandoned.capture = async (job): Promise<void> => {\n await notifyCaptureStuck(options, config, logger, job.buildId, delivery.publicOrigin);\n };\n const inProcess = createCaptureHandler(handlerOptions);\n const handler = shouldForkCapture(testing, logger)\n ? forkedHandler(options, { fallback: inProcess, retries, onCrashed: failed, logger })\n : inProcess;\n return {\n queue,\n enqueueCapture,\n handler: alerting(handler, retries, async (buildId) => {\n await notifyCaptureFailed(options, config, logger, buildId, delivery.publicOrigin);\n }),\n };\n}\n\nfunction captureHandlerOptions(\n options: ShelfOptions,\n config: ShelfConfig,\n delivery: Delivery,\n logger: Logger,\n parts: { runner: CaptureRunner; enqueue: CaptureHandlerOptions[\"enqueue\"] },\n): CaptureHandlerOptions {\n return {\n db: options.database,\n storage: options.storage,\n runner: parts.runner,\n // `resolveShelfOptions` defaults scratchDir; the fallback covers hand-built configs.\n scratchDir: config.scratchDir ?? DEFAULT_SCRATCH_DIR,\n viewports: config.viewports,\n logger,\n secret: credentialKeys(config),\n design: options.design,\n shardSize: options.testing?.shardSize,\n notifiers: delivery.notifiers,\n buildState: delivery.buildState,\n publicOrigin: delivery.publicOrigin,\n config,\n enqueue: parts.enqueue,\n maxRetries: options.testing?.retries,\n };\n}\n\nfunction forkedHandler(\n options: ShelfOptions,\n parts: {\n fallback: KindHandler;\n retries: number;\n onCrashed: (job: ConsumerJob, error: string) => Promise<void>;\n logger: Logger;\n },\n): CaptureHandler {\n const testing = options.testing;\n return createForkedHandler({\n workerEntry: testing?.workerEntry ?? \"\",\n shardSize: testing?.shardSize,\n imageEngine: testing?.images?.engine,\n diffThreads: testing?.compare?.threads,\n ...parts,\n });\n}\n\n/**\n * Alert admins when a capture left its build failed: after a run that ended, and after a final\n * attempt that threw (the build may then already be failed by a crash hook). Alerts stay in this\n * process whichever process rendered.\n */\nfunction alerting(\n inner: CaptureHandler,\n retries: number,\n alert: (buildId: string) => Promise<void>,\n): CaptureHandler {\n return {\n accepts: (job) => inner.accepts?.(job) !== false,\n superseded: async (job) => (await inner.superseded?.(job)) === true,\n run: async (job, context) => {\n try {\n await inner.run(job, context);\n } catch (error) {\n if (isFinalAttempt(job, retries)) {\n await alert(job.buildId);\n }\n throw error;\n }\n await alert(job.buildId);\n },\n cancel: async (job) => {\n await inner.cancel?.(job);\n },\n ...(inner.close ? { close: inner.close } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;AAqDA,SAAS,YAAY,OAAyE;CAC5F,OAAO,OAAO,SAAS,UAAU;EAC/B,MAAM,cAAc,mBAAmB;EACvC,MAAM,MAAM,QAAQ;GAAE;GAAS;GAAO,GAAI,cAAc,EAAE,YAAY,IAAI,CAAC;EAAG,CAAC;CACjF;AACF;;;;;AAMA,SAAgB,aACd,SACA,QACA,UACA,QACA,MACe;CACf,MAAM,UAAU,QAAQ;CACxB,IAAI,YAAY,KAAA,GACd,OAAO;EAAE,OAAO;EAAM,gBAAgB,KAAA;EAAW,SAAS;CAAK;CAEjE,MAAM,QAAQ,KAAK;CACnB,MAAM,iBAAiB,YAAY,KAAK;CACxC,MAAM,iBAAiB,sBAAsB,SAAS,QAAQ,UAAU,QAAQ;EAC9E,QAAQ,QAAQ;EAChB,SAAS,OAAO,QAAQ;GACtB,MAAM,MAAM,QAAQ,GAAG;EACzB;CACF,CAAC;CACD,MAAM,UAAU,QAAQ,SAAS,WAAW;CAC5C,MAAM,WAAW,oBAAoB,gBAAgB,OAAO;CAC5D,MAAM,SAAS,OAAO,KAAkB,UAAiC;EACvE,MAAM,mBAAmB,UAAU,KAAK,KAAK;EAC7C,MAAM,oBAAoB,SAAS,QAAQ,QAAQ,IAAI,SAAS,SAAS,YAAY;CACvF;CACA,KAAK,UAAU,UAAU;CACzB,KAA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ACR;GACA,MAAM,MAAM,IAAI,OAAO;EACzB;EACA,QAAQ,OAAO,QAAQ;GACrB,MAAM,MAAM,SAAS,GAAG;EAC1B;EACA,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;CAC9C;AACF"}
|
|
1
|
+
{"version":3,"file":"capture-setup.mjs","names":[],"sources":["../src/capture-setup.ts"],"sourcesContent":["/**\n * Capture wiring (ADR 0006, decisions 4 to 6): where uploads queue their capture, and the handler\n * of `capture` jobs. Captures queue on the shared database queue. The handler runs them in this process, or in a forked child the parent pushes jobs\n * to (`testing.workerEntry`). The consumer that polls the queue and calls the handler is built\n * in `jobs-setup.ts`.\n */\nimport type { CaptureQueue } from \"@storyshelf/core/adapter/capture-queue\";\nimport type { CaptureRunner } from \"@storyshelf/core/adapter/capture-runner\";\nimport type { NotifierProvider } from \"@storyshelf/core/adapter/notifier\";\nimport {\n captureDispatchDeps,\n createCaptureHandler,\n DEFAULT_RETRIES,\n failCrashedCapture,\n isFinalAttempt,\n type BuildStatePublisher,\n type CaptureHandlerOptions,\n type ConsumerJob,\n type KindHandler,\n} from \"@storyshelf/core/capture\";\nimport { DEFAULT_SCRATCH_DIR } from \"@storyshelf/core/config\";\nimport type { ShelfConfig, ShelfOptions } from \"@storyshelf/core/config\";\nimport type { Logger } from \"@storyshelf/core/logger\";\nimport { currentTraceparent } from \"@storyshelf/observability\";\nimport { notifyCaptureFailed, notifyCaptureStuck } from \"./capture-alerts.ts\";\nimport { createForkedHandler, shouldForkCapture } from \"./capture-process.ts\";\nimport { credentialKeys } from \"./credential-keys.ts\";\nimport type { JobQueue } from \"./job-queue.ts\";\n\n/** The `capture` handler, with a way to stop a forked child once the consumer has drained. */\nexport interface CaptureHandler extends KindHandler {\n close?: () => Promise<void>;\n}\n\n/** What uploads and the consumer need of capture. */\nexport interface CaptureWiring {\n /** Where captures queue: the database queue, or null without `testing`. */\n queue: CaptureQueue | null;\n /** Queues a capture for a build; undefined without `testing`. */\n enqueueCapture: ((buildId: string, reqId?: string) => Promise<void>) | undefined;\n /** Runs `capture` jobs here; null without `testing`. */\n handler: CaptureHandler | null;\n}\n\n/** What a capture hands its results to. */\ninterface Delivery {\n notifiers: NotifierProvider[];\n buildState: BuildStatePublisher;\n /** The resolved public origin (ADR 0007): status links and targets that need a URL use it. */\n publicOrigin: () => Promise<string | undefined>;\n}\n\n/** Queue a build, continuing the active request trace when present. */\nfunction enqueuerFor(queue: CaptureQueue): (buildId: string, reqId?: string) => Promise<void> {\n return async (buildId, reqId) => {\n const traceparent = currentTraceparent();\n await queue.enqueue({ buildId, reqId, ...(traceparent ? { traceparent } : {}) });\n };\n}\n\n/**\n * Wire capture for `options`: `testing` always has a runner, so this instance consumes the\n * captures it queues. Shard jobs go back onto the same queue the capture came from.\n */\nexport function setupCapture(\n options: ShelfOptions,\n config: ShelfConfig,\n delivery: Delivery,\n logger: Logger,\n jobs: JobQueue,\n): CaptureWiring {\n const testing = options.testing;\n if (testing === undefined) {\n return { queue: null, enqueueCapture: undefined, handler: null };\n }\n const queue = jobs.view;\n const enqueueCapture = enqueuerFor(queue);\n const handlerOptions = captureHandlerOptions(options, config, delivery, logger, {\n runner: testing.runner,\n enqueue: async (job) => {\n await queue.enqueue(job);\n },\n });\n const retries = options.testing?.retries ?? DEFAULT_RETRIES;\n const dispatch = captureDispatchDeps(handlerOptions, retries);\n const failed = async (job: ConsumerJob, error: string): Promise<void> => {\n await failCrashedCapture(dispatch, job, error);\n await notifyCaptureFailed(options, config, logger, job.buildId, delivery.publicOrigin);\n };\n jobs.exhausted.capture = failed;\n jobs.abandoned.capture = async (job): Promise<void> => {\n await notifyCaptureStuck(options, config, logger, job.buildId, delivery.publicOrigin);\n };\n const inProcess = createCaptureHandler(handlerOptions);\n const handler = shouldForkCapture(testing, logger)\n ? forkedHandler(options, { fallback: inProcess, retries, onCrashed: failed, logger })\n : inProcess;\n return {\n queue,\n enqueueCapture,\n handler: alerting(handler, retries, async (buildId) => {\n await notifyCaptureFailed(options, config, logger, buildId, delivery.publicOrigin);\n }),\n };\n}\n\nfunction captureHandlerOptions(\n options: ShelfOptions,\n config: ShelfConfig,\n delivery: Delivery,\n logger: Logger,\n parts: { runner: CaptureRunner; enqueue: CaptureHandlerOptions[\"enqueue\"] },\n): CaptureHandlerOptions {\n return {\n db: options.database,\n storage: options.storage,\n runner: parts.runner,\n // `resolveShelfOptions` defaults scratchDir; the fallback covers hand-built configs.\n scratchDir: config.scratchDir ?? DEFAULT_SCRATCH_DIR,\n viewports: config.viewports,\n logger,\n secret: credentialKeys(config),\n design: options.design,\n shardSize: options.testing?.shardSize,\n notifiers: delivery.notifiers,\n buildState: delivery.buildState,\n publicOrigin: delivery.publicOrigin,\n config,\n enqueue: parts.enqueue,\n maxRetries: options.testing?.retries,\n };\n}\n\nfunction forkedHandler(\n options: ShelfOptions,\n parts: {\n fallback: KindHandler;\n retries: number;\n onCrashed: (job: ConsumerJob, error: string) => Promise<void>;\n logger: Logger;\n },\n): CaptureHandler {\n const testing = options.testing;\n return createForkedHandler({\n workerEntry: testing?.workerEntry ?? \"\",\n shardSize: testing?.shardSize,\n imageEngine: testing?.images?.engine,\n diffThreads: testing?.compare?.threads,\n ...parts,\n });\n}\n\n/**\n * Alert admins when a capture left its build failed: after a run that ended, and after a final\n * attempt that threw (the build may then already be failed by a crash hook). Alerts stay in this\n * process whichever process rendered.\n */\nfunction alerting(\n inner: CaptureHandler,\n retries: number,\n alert: (buildId: string) => Promise<void>,\n): CaptureHandler {\n return {\n accepts: (job) => inner.accepts?.(job) !== false,\n deadlineExceeded: async (job, seconds) => {\n await inner.deadlineExceeded?.(job, seconds);\n },\n superseded: async (job) => (await inner.superseded?.(job)) === true,\n run: async (job, context) => {\n try {\n await inner.run(job, context);\n } catch (error) {\n if (isFinalAttempt(job, retries)) {\n await alert(job.buildId);\n }\n throw error;\n }\n await alert(job.buildId);\n },\n cancel: async (job) => {\n await inner.cancel?.(job);\n },\n ...(inner.close ? { close: inner.close } : {}),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,SACA,QACA,UACA,QACA,OACuB;CACvB,OAAO;EACL,IAAI,QAAQ;EACZ,SAAS,QAAQ;EACjB,QAAQ,MAAM;EAEd,YAAY,OAAO,cAAc;EACjC,WAAW,OAAO;EAClB;EACA,QAAQ,eAAe,MAAM;EAC7B,QAAQ,QAAQ;EAChB,WAAW,QAAQ,SAAS;EAC5B,WAAW,SAAS;EACpB,YAAY,SAAS;EACrB,cAAc,SAAS;EACvB;EACA,SAAS,MAAM;EACf,YAAY,QAAQ,SAAS;CAC/B;AACF;AAEA,SAAS,cACP,SACA,OAMgB;CAChB,MAAM,UAAU,QAAQ;CACxB,OAAO,oBAAoB;EACzB,aAAa,SAAS,eAAe;EACrC,WAAW,SAAS;EACpB,aAAa,SAAS,QAAQ;EAC9B,aAAa,SAAS,SAAS;EAC/B,GAAG;CACL,CAAC;AACH;;;;;;AAOA,SAAS,SACP,OACA,SACA,OACgB;CAChB,OAAO;EACL,UAAU,QAAQ,MAAM,UAAU,GAAG,MAAM;EAC3C,kBAAkB,OAAO,KAAK,YAAY;GACxC,MAAM,MAAM,mBAAmB,KAAK,OAAO;EAC7C;EACA,YAAY,OAAO,QAAS,MAAM,MAAM,aAAa,GAAG,MAAO;EAC/D,KAAK,OAAO,KAAK,YAAY;GAC3B,IAAI;IACF,MAAM,MAAM,IAAI,KAAK,OAAO;GAC9B,SAAS,OAAO;IACd,IAAI,eAAe,KAAK,OAAO,GAC7B,MAAM,MAAM,IAAI,OAAO;IAEzB,MAAM;GACR;GACA,MAAM,MAAM,IAAI,OAAO;EACzB;EACA,QAAQ,OAAO,QAAQ;GACrB,MAAM,MAAM,SAAS,GAAG;EAC1B;EACA,GAAI,MAAM,QAAQ,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;CAC9C;AACF"}
|
package/dist/index.mjs
CHANGED
|
@@ -380,7 +380,7 @@ function registerDocs(app) {
|
|
|
380
380
|
* from source (dev server, tests).
|
|
381
381
|
*/
|
|
382
382
|
function packageVersion() {
|
|
383
|
-
return "0.10.0-next-
|
|
383
|
+
return "0.10.0-next-ccff478";
|
|
384
384
|
}
|
|
385
385
|
export { createAuthSystemHook, createShelfApp, createShelfLogger };
|
|
386
386
|
|
package/dist/jobs-setup.mjs
CHANGED
|
@@ -82,7 +82,8 @@ function databaseConsumer(options, runtime, jobs, wiring) {
|
|
|
82
82
|
},
|
|
83
83
|
config: {
|
|
84
84
|
concurrency: capturesHere ? options.testing?.concurrency : 1,
|
|
85
|
-
maxRetries: options.testing?.retries ?? DEFAULT_RETRIES
|
|
85
|
+
maxRetries: options.testing?.retries ?? DEFAULT_RETRIES,
|
|
86
|
+
...maxJobConfig(options)
|
|
86
87
|
},
|
|
87
88
|
scratchDir: runtime.config.scratchDir ?? DEFAULT_SCRATCH_DIR,
|
|
88
89
|
metrics: jobMetrics(),
|
|
@@ -103,7 +104,10 @@ function notifyConsumer(options, runtime, queue, handler) {
|
|
|
103
104
|
return lazyConsumer(() => ({
|
|
104
105
|
queue: queue.get(),
|
|
105
106
|
handlers: { notify: handler },
|
|
106
|
-
config: {
|
|
107
|
+
config: {
|
|
108
|
+
concurrency: NOTIFY_CONCURRENCY,
|
|
109
|
+
...maxJobConfig(options)
|
|
110
|
+
},
|
|
107
111
|
metrics: jobMetrics(),
|
|
108
112
|
logger: runtime.logger.child({ component: "notify-consumer" }),
|
|
109
113
|
...options.testing?.queueClock === void 0 ? {} : {
|
|
@@ -152,6 +156,11 @@ function reviewRequestedFor(options, runtime) {
|
|
|
152
156
|
}));
|
|
153
157
|
};
|
|
154
158
|
}
|
|
159
|
+
/** The consumer's wall-clock bound for one job, when `testing.maxJobSeconds` states it. */
|
|
160
|
+
function maxJobConfig(options) {
|
|
161
|
+
const seconds = options.testing?.maxJobSeconds;
|
|
162
|
+
return seconds === void 0 ? {} : { maxJobSeconds: seconds };
|
|
163
|
+
}
|
|
155
164
|
export { setupJobs };
|
|
156
165
|
|
|
157
166
|
//# sourceMappingURL=jobs-setup.mjs.map
|
package/dist/jobs-setup.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jobs-setup.mjs","names":["isServerlessHost"],"sources":["../src/jobs-setup.ts"],"sourcesContent":["/**\n * Background jobs of the app (ADR 0006): the one database queue, the handlers of its job kinds\n * (`capture` with `testing`, `publish` on a long-running host, `notify` on a queue of its own) and the one consumer that runs\n * them.\n */\nimport {\n DEFAULT_RETRIES,\n NOTIFY_MAX_ATTEMPTS,\n type BuildStatePublisher,\n type CaptureConsumer,\n type KindHandler,\n} from \"@storyshelf/core/capture\";\nimport type { ShelfOptions } from \"@storyshelf/core/config\";\nimport { DEFAULT_SCRATCH_DIR } from \"@storyshelf/core/config\";\nimport type { Build, CaptureJobKind, Project } from \"@storyshelf/core/schema\";\nimport { setupBuildState, type BuildStateWiring } from \"./build-state-setup.ts\";\nimport { setupCapture, type CaptureWiring } from \"./capture-setup.ts\";\nimport { combineConsumers, jobMetrics, lazyConsumer } from \"./consumer-setup.ts\";\nimport { createJobCanceller, type JobCanceller } from \"./job-canceller.ts\";\nimport { createJobQueue, type JobQueue } from \"./job-queue.ts\";\nimport { notifyAssignedWith, type NotifyDeps } from \"./notify.ts\";\nimport { setupPublishing, type PublishService, type PublishWiring } from \"./publish-setup.ts\";\nimport {\n assignedReviewersOf,\n assignmentReason,\n type AssignedReviewer,\n} from \"./review-assignment.ts\";\nimport { announceReviewWith, REVIEW_EVENTS, reviewRequestedData } from \"./review-events.ts\";\nimport type { ServerRuntime } from \"./runtime.ts\";\nimport { isServerlessHost } from \"./serverless.ts\";\n\n/** What the rest of the app takes from the job wiring. */\nexport interface JobsWiring {\n /** Where captures queue; null without `testing`. */\n captureQueue: CaptureWiring[\"queue\"];\n enqueueCapture: CaptureWiring[\"enqueueCapture\"];\n /** Whether this instance runs the capture jobs (the retry and compute-jobs UI applies). */\n capturesHere: boolean;\n publish: PublishService;\n /** Asks for a build's current state to be shown on its git channels (ADR 0014). */\n buildState: BuildStatePublisher;\n /** Cancels every unfinished job of a build, of any kind (capture, publish, notify). */\n cancelBuildJobs: JobCanceller;\n /** Runs every handler this instance has; null when it consumes nothing. */\n consumer: CaptureConsumer | null;\n}\n\n/** Wire the queue, the handlers and the consumer for `options`. */\nexport function setupJobs(\n options: ShelfOptions,\n runtime: ServerRuntime,\n env: NodeJS.ProcessEnv = process.env,\n): JobsWiring {\n const { jobs, notifyJobs } = queuesFor(options, isServerlessHost(env));\n const buildState = setupBuildState(options, runtime, notifyJobs);\n const capture = setupCapture(\n options,\n runtime.config,\n {\n notifiers: runtime.notifiers,\n buildState: buildState.publisher,\n publicOrigin: async () => await runtime.publicOrigin.url(),\n },\n runtime.logger,\n jobs,\n );\n const publishing = setupPublishing(\n options,\n runtime.config,\n runtime.logger,\n capture.enqueueCapture !== undefined,\n {\n jobs,\n buildState: buildState.publisher,\n reviewRequested: reviewRequestedFor(options, runtime),\n },\n );\n const wiring = { capture, publishing, buildState, notifyJobs };\n return {\n captureQueue: capture.queue,\n enqueueCapture: capture.enqueueCapture,\n capturesHere: capture.handler !== null,\n publish: publishing,\n buildState: buildState.publisher,\n cancelBuildJobs: createJobCanceller([jobs.view]),\n consumer: combineConsumers(consumersOf(options, runtime, jobs, wiring)),\n };\n}\n\n/**\n * The database queue (captures with `testing`, publishing on a long-running host) and,\n * on a long-running host, a queue of its own for `notify` jobs: a status must not wait behind a\n * capture that holds every slot for minutes.\n */\nfunction queuesFor(\n options: ShelfOptions,\n serverless: boolean,\n): { jobs: JobQueue; notifyJobs: JobQueue | null } {\n const testing = options.testing;\n const databaseCaptures = testing?.runner !== undefined;\n const kinds: CaptureJobKind[] = [\n ...(databaseCaptures ? ([\"capture\"] as const) : []),\n ...(serverless ? [] : ([\"publish\"] as const)),\n ];\n return {\n jobs: createJobQueue(options, kinds, testing?.retries ?? DEFAULT_RETRIES),\n notifyJobs: serverless ? null : createJobQueue(options, [\"notify\"], NOTIFY_MAX_ATTEMPTS - 1),\n };\n}\n\n/** Every consumer this instance runs; none on a host that polls nothing. */\nfunction consumersOf(\n options: ShelfOptions,\n runtime: ServerRuntime,\n jobs: JobQueue,\n wiring: {\n capture: CaptureWiring;\n publishing: Pick<PublishWiring, \"handler\">;\n buildState: Pick<BuildStateWiring, \"handler\">;\n notifyJobs: JobQueue | null;\n },\n): CaptureConsumer[] {\n const { capture, publishing, buildState, notifyJobs } = wiring;\n return [\n ...(jobs.kinds.length > 0\n ? [databaseConsumer(options, runtime, jobs, { capture, publishing })]\n : []),\n ...(buildState.handler !== null && notifyJobs !== null\n ? [notifyConsumer(options, runtime, notifyJobs, buildState.handler)]\n : []),\n ];\n}\n\n/** The consumer of the database queue: capture and publish jobs. */\nfunction databaseConsumer(\n options: ShelfOptions,\n runtime: ServerRuntime,\n jobs: JobQueue,\n wiring: {\n capture: CaptureWiring;\n publishing: Pick<PublishWiring, \"handler\">;\n },\n): CaptureConsumer {\n const { capture, publishing } = wiring;\n const capturesHere = jobs.kinds.includes(\"capture\");\n return lazyConsumer(\n () => ({\n queue: jobs.get(),\n handlers: {\n ...(capturesHere && capture.handler ? { capture: capture.handler } : {}),\n ...(publishing.handler ? { publish: publishing.handler } : {}),\n },\n // Publishing alone is one job at a time, so a big zip never crowds out the web server.\n config: {\n concurrency: capturesHere ? options.testing?.concurrency : 1,\n maxRetries: options.testing?.retries ?? DEFAULT_RETRIES,\n },\n scratchDir: runtime.config.scratchDir ?? DEFAULT_SCRATCH_DIR,\n metrics: jobMetrics(),\n logger: runtime.logger.child({ component: \"job-consumer\" }),\n ...(options.testing?.queueClock === undefined\n ? {}\n : { now: options.testing.queueClock.now, timers: options.testing.queueClock.timers }),\n }),\n [\n async () => {\n if (capturesHere) {\n await capture.handler?.close?.();\n }\n await jobs.built()?.lifecycle.teardown();\n },\n ],\n );\n}\n\n/** Deliveries running at once: short HTTP calls to a git host, bounded to stay clear of its rate limits. */\nconst NOTIFY_CONCURRENCY = 4;\n\n/** The consumer of `notify` jobs, on its own queue so no capture or publish job can starve it. */\nfunction notifyConsumer(\n options: ShelfOptions,\n runtime: ServerRuntime,\n queue: JobQueue,\n handler: KindHandler,\n): CaptureConsumer {\n return lazyConsumer(\n () => ({\n queue: queue.get(),\n handlers: { notify: handler },\n config: { concurrency: NOTIFY_CONCURRENCY },\n metrics: jobMetrics(),\n logger: runtime.logger.child({ component: \"notify-consumer\" }),\n ...(options.testing?.queueClock === undefined\n ? {}\n : { now: options.testing.queueClock.now, timers: options.testing.queueClock.timers }),\n }),\n [\n async () => {\n await queue.built()?.lifecycle.teardown();\n },\n ],\n );\n}\n\n/**\n * The reviewers the component owners assign to a build (#465). Best-effort: a failed lookup logs and\n * leaves the request to the default recipients, so a broken rule never swallows a review request.\n */\nasync function assignedOrNone(\n deps: Pick<NotifyDeps, \"db\" | \"logger\">,\n project: Project,\n build: Build,\n): Promise<AssignedReviewer[]> {\n try {\n return await assignedReviewersOf(deps.db, project, build);\n } catch (error) {\n deps.logger.warn({ err: error, buildId: build.id }, \"component owners could not be resolved\");\n return [];\n }\n}\n\n/** Tells the project's reviewers a published build waits for a verdict (webhook and notifications). */\nfunction reviewRequestedFor(\n options: ShelfOptions,\n runtime: ServerRuntime,\n): (project: Project, build: Build) => Promise<void> {\n return async (project, build) => {\n const deps = {\n db: options.database,\n config: runtime.config,\n ui: runtime.ui,\n logger: runtime.logger,\n notifiers: runtime.notifiers,\n notificationsConfig: options.notifications?.config,\n publicOrigin: runtime.publicOrigin,\n };\n const assigned = await assignedOrNone(deps, project, build);\n await announceReviewWith(\n deps,\n project,\n REVIEW_EVENTS.requested,\n reviewRequestedData(build),\n build.id,\n { skipUsers: new Set(assigned.map((reviewer) => reviewer.userId)) },\n );\n await Promise.all(\n assigned.map(async (reviewer) => {\n const data = {\n ...reviewRequestedData(build),\n assignedBecause: assignmentReason(reviewer.components),\n };\n await notifyAssignedWith(deps, project, reviewer.userId, data, `/builds/${build.id}`);\n }),\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,UACd,SACA,SACA,MAAyB,QA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AO;CACvF,IACA,CACE,YAAY;EACV,MAAM,MAAM,MAAM,CAAC,EAAE,UAAU,SAAS;CAC1C,CACF,CACF;AACF;;;;;AAMA,eAAe,eACb,MACA,SACA,OAC6B;CAC7B,IAAI;EACF,OAAO,MAAM,oBAAoB,KAAK,IAAI,SAAS,KAAK;CAC1D,SAAS,OAAO;EACd,KAAK,OAAO,KAAK;GAAE,KAAK;GAAO,SAAS,MAAM;EAAG,GAAG,wCAAwC;EAC5F,OAAO,CAAC;CACV;AACF;;AAGA,SAAS,mBACP,SACA,SACmD;CACnD,OAAO,OAAO,SAAS,UAAU;EAC/B,MAAM,OAAO;GACX,IAAI,QAAQ;GACZ,QAAQ,QAAQ;GAChB,IAAI,QAAQ;GACZ,QAAQ,QAAQ;GAChB,WAAW,QAAQ;GACnB,qBAAqB,QAAQ,eAAe;GAC5C,cAAc,QAAQ;EACxB;EACA,MAAM,WAAW,MAAM,eAAe,MAAM,SAAS,KAAK;EAC1D,MAAM,mBACJ,MACA,SACA,cAAc,WACd,oBAAoB,KAAK,GACzB,MAAM,IACN,EAAE,WAAW,IAAI,IAAI,SAAS,KAAK,aAAa,SAAS,MAAM,CAAC,EAAE,CACpE;EACA,MAAM,QAAQ,IACZ,SAAS,IAAI,OAAO,aAAa;GAC/B,MAAM,OAAO;IACX,GAAG,oBAAoB,KAAK;IAC5B,iBAAiB,iBAAiB,SAAS,UAAU;GACvD;GACA,MAAM,mBAAmB,MAAM,SAAS,SAAS,QAAQ,MAAM,WAAW,MAAM,IAAI;EACtF,CAAC,CACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"jobs-setup.mjs","names":["isServerlessHost"],"sources":["../src/jobs-setup.ts"],"sourcesContent":["/**\n * Background jobs of the app (ADR 0006): the one database queue, the handlers of its job kinds\n * (`capture` with `testing`, `publish` on a long-running host, `notify` on a queue of its own) and the one consumer that runs\n * them.\n */\nimport {\n DEFAULT_RETRIES,\n NOTIFY_MAX_ATTEMPTS,\n type BuildStatePublisher,\n type CaptureConsumer,\n type KindHandler,\n} from \"@storyshelf/core/capture\";\nimport type { ShelfOptions } from \"@storyshelf/core/config\";\nimport { DEFAULT_SCRATCH_DIR } from \"@storyshelf/core/config\";\nimport type { Build, CaptureJobKind, Project } from \"@storyshelf/core/schema\";\nimport { setupBuildState, type BuildStateWiring } from \"./build-state-setup.ts\";\nimport { setupCapture, type CaptureWiring } from \"./capture-setup.ts\";\nimport { combineConsumers, jobMetrics, lazyConsumer } from \"./consumer-setup.ts\";\nimport { createJobCanceller, type JobCanceller } from \"./job-canceller.ts\";\nimport { createJobQueue, type JobQueue } from \"./job-queue.ts\";\nimport { notifyAssignedWith, type NotifyDeps } from \"./notify.ts\";\nimport { setupPublishing, type PublishService, type PublishWiring } from \"./publish-setup.ts\";\nimport {\n assignedReviewersOf,\n assignmentReason,\n type AssignedReviewer,\n} from \"./review-assignment.ts\";\nimport { announceReviewWith, REVIEW_EVENTS, reviewRequestedData } from \"./review-events.ts\";\nimport type { ServerRuntime } from \"./runtime.ts\";\nimport { isServerlessHost } from \"./serverless.ts\";\n\n/** What the rest of the app takes from the job wiring. */\nexport interface JobsWiring {\n /** Where captures queue; null without `testing`. */\n captureQueue: CaptureWiring[\"queue\"];\n enqueueCapture: CaptureWiring[\"enqueueCapture\"];\n /** Whether this instance runs the capture jobs (the retry and compute-jobs UI applies). */\n capturesHere: boolean;\n publish: PublishService;\n /** Asks for a build's current state to be shown on its git channels (ADR 0014). */\n buildState: BuildStatePublisher;\n /** Cancels every unfinished job of a build, of any kind (capture, publish, notify). */\n cancelBuildJobs: JobCanceller;\n /** Runs every handler this instance has; null when it consumes nothing. */\n consumer: CaptureConsumer | null;\n}\n\n/** Wire the queue, the handlers and the consumer for `options`. */\nexport function setupJobs(\n options: ShelfOptions,\n runtime: ServerRuntime,\n env: NodeJS.ProcessEnv = process.env,\n): JobsWiring {\n const { jobs, notifyJobs } = queuesFor(options, isServerlessHost(env));\n const buildState = setupBuildState(options, runtime, notifyJobs);\n const capture = setupCapture(\n options,\n runtime.config,\n {\n notifiers: runtime.notifiers,\n buildState: buildState.publisher,\n publicOrigin: async () => await runtime.publicOrigin.url(),\n },\n runtime.logger,\n jobs,\n );\n const publishing = setupPublishing(\n options,\n runtime.config,\n runtime.logger,\n capture.enqueueCapture !== undefined,\n {\n jobs,\n buildState: buildState.publisher,\n reviewRequested: reviewRequestedFor(options, runtime),\n },\n );\n const wiring = { capture, publishing, buildState, notifyJobs };\n return {\n captureQueue: capture.queue,\n enqueueCapture: capture.enqueueCapture,\n capturesHere: capture.handler !== null,\n publish: publishing,\n buildState: buildState.publisher,\n cancelBuildJobs: createJobCanceller([jobs.view]),\n consumer: combineConsumers(consumersOf(options, runtime, jobs, wiring)),\n };\n}\n\n/**\n * The database queue (captures with `testing`, publishing on a long-running host) and,\n * on a long-running host, a queue of its own for `notify` jobs: a status must not wait behind a\n * capture that holds every slot for minutes.\n */\nfunction queuesFor(\n options: ShelfOptions,\n serverless: boolean,\n): { jobs: JobQueue; notifyJobs: JobQueue | null } {\n const testing = options.testing;\n const databaseCaptures = testing?.runner !== undefined;\n const kinds: CaptureJobKind[] = [\n ...(databaseCaptures ? ([\"capture\"] as const) : []),\n ...(serverless ? [] : ([\"publish\"] as const)),\n ];\n return {\n jobs: createJobQueue(options, kinds, testing?.retries ?? DEFAULT_RETRIES),\n notifyJobs: serverless ? null : createJobQueue(options, [\"notify\"], NOTIFY_MAX_ATTEMPTS - 1),\n };\n}\n\n/** Every consumer this instance runs; none on a host that polls nothing. */\nfunction consumersOf(\n options: ShelfOptions,\n runtime: ServerRuntime,\n jobs: JobQueue,\n wiring: {\n capture: CaptureWiring;\n publishing: Pick<PublishWiring, \"handler\">;\n buildState: Pick<BuildStateWiring, \"handler\">;\n notifyJobs: JobQueue | null;\n },\n): CaptureConsumer[] {\n const { capture, publishing, buildState, notifyJobs } = wiring;\n return [\n ...(jobs.kinds.length > 0\n ? [databaseConsumer(options, runtime, jobs, { capture, publishing })]\n : []),\n ...(buildState.handler !== null && notifyJobs !== null\n ? [notifyConsumer(options, runtime, notifyJobs, buildState.handler)]\n : []),\n ];\n}\n\n/** The consumer of the database queue: capture and publish jobs. */\nfunction databaseConsumer(\n options: ShelfOptions,\n runtime: ServerRuntime,\n jobs: JobQueue,\n wiring: {\n capture: CaptureWiring;\n publishing: Pick<PublishWiring, \"handler\">;\n },\n): CaptureConsumer {\n const { capture, publishing } = wiring;\n const capturesHere = jobs.kinds.includes(\"capture\");\n return lazyConsumer(\n () => ({\n queue: jobs.get(),\n handlers: {\n ...(capturesHere && capture.handler ? { capture: capture.handler } : {}),\n ...(publishing.handler ? { publish: publishing.handler } : {}),\n },\n // Publishing alone is one job at a time, so a big zip never crowds out the web server.\n config: {\n concurrency: capturesHere ? options.testing?.concurrency : 1,\n maxRetries: options.testing?.retries ?? DEFAULT_RETRIES,\n ...maxJobConfig(options),\n },\n scratchDir: runtime.config.scratchDir ?? DEFAULT_SCRATCH_DIR,\n metrics: jobMetrics(),\n logger: runtime.logger.child({ component: \"job-consumer\" }),\n ...(options.testing?.queueClock === undefined\n ? {}\n : { now: options.testing.queueClock.now, timers: options.testing.queueClock.timers }),\n }),\n [\n async () => {\n if (capturesHere) {\n await capture.handler?.close?.();\n }\n await jobs.built()?.lifecycle.teardown();\n },\n ],\n );\n}\n\n/** Deliveries running at once: short HTTP calls to a git host, bounded to stay clear of its rate limits. */\nconst NOTIFY_CONCURRENCY = 4;\n\n/** The consumer of `notify` jobs, on its own queue so no capture or publish job can starve it. */\nfunction notifyConsumer(\n options: ShelfOptions,\n runtime: ServerRuntime,\n queue: JobQueue,\n handler: KindHandler,\n): CaptureConsumer {\n return lazyConsumer(\n () => ({\n queue: queue.get(),\n handlers: { notify: handler },\n config: { concurrency: NOTIFY_CONCURRENCY, ...maxJobConfig(options) },\n metrics: jobMetrics(),\n logger: runtime.logger.child({ component: \"notify-consumer\" }),\n ...(options.testing?.queueClock === undefined\n ? {}\n : { now: options.testing.queueClock.now, timers: options.testing.queueClock.timers }),\n }),\n [\n async () => {\n await queue.built()?.lifecycle.teardown();\n },\n ],\n );\n}\n\n/**\n * The reviewers the component owners assign to a build (#465). Best-effort: a failed lookup logs and\n * leaves the request to the default recipients, so a broken rule never swallows a review request.\n */\nasync function assignedOrNone(\n deps: Pick<NotifyDeps, \"db\" | \"logger\">,\n project: Project,\n build: Build,\n): Promise<AssignedReviewer[]> {\n try {\n return await assignedReviewersOf(deps.db, project, build);\n } catch (error) {\n deps.logger.warn({ err: error, buildId: build.id }, \"component owners could not be resolved\");\n return [];\n }\n}\n\n/** Tells the project's reviewers a published build waits for a verdict (webhook and notifications). */\nfunction reviewRequestedFor(\n options: ShelfOptions,\n runtime: ServerRuntime,\n): (project: Project, build: Build) => Promise<void> {\n return async (project, build) => {\n const deps = {\n db: options.database,\n config: runtime.config,\n ui: runtime.ui,\n logger: runtime.logger,\n notifiers: runtime.notifiers,\n notificationsConfig: options.notifications?.config,\n publicOrigin: runtime.publicOrigin,\n };\n const assigned = await assignedOrNone(deps, project, build);\n await announceReviewWith(\n deps,\n project,\n REVIEW_EVENTS.requested,\n reviewRequestedData(build),\n build.id,\n { skipUsers: new Set(assigned.map((reviewer) => reviewer.userId)) },\n );\n await Promise.all(\n assigned.map(async (reviewer) => {\n const data = {\n ...reviewRequestedData(build),\n assignedBecause: assignmentReason(reviewer.components),\n };\n await notifyAssignedWith(deps, project, reviewer.userId, data, `/builds/${build.id}`);\n }),\n );\n };\n}\n\n/** The consumer's wall-clock bound for one job, when `testing.maxJobSeconds` states it. */\nfunction maxJobConfig(options: ShelfOptions): { maxJobSeconds?: number } {\n const seconds = options.testing?.maxJobSeconds;\n return seconds === undefined ? {} : { maxJobSeconds: seconds };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,UACd,SACA,SACA,MAAyB,QAAQ,KACrB;CACZ,MAAM,EAAE,MAAM,eAAe,UAAU,SAASA,mBAAiB,GAAG,CAAC;CACrE,MAAM,aAAa,gBAAgB,SAA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,UAAU,SAAS;CAC1C,CACF,CACF;AACF;;;;;AAMA,eAAe,eACb,MACA,SACA,OAC6B;CAC7B,IAAI;EACF,OAAO,MAAM,oBAAoB,KAAK,IAAI,SAAS,KAAK;CAC1D,SAAS,OAAO;EACd,KAAK,OAAO,KAAK;GAAE,KAAK;GAAO,SAAS,MAAM;EAAG,GAAG,wCAAwC;EAC5F,OAAO,CAAC;CACV;AACF;;AAGA,SAAS,mBACP,SACA,SACmD;CACnD,OAAO,OAAO,SAAS,UAAU;EAC/B,MAAM,OAAO;GACX,IAAI,QAAQ;GACZ,QAAQ,QAAQ;GAChB,IAAI,QAAQ;GACZ,QAAQ,QAAQ;GAChB,WAAW,QAAQ;GACnB,qBAAqB,QAAQ,eAAe;GAC5C,cAAc,QAAQ;EACxB;EACA,MAAM,WAAW,MAAM,eAAe,MAAM,SAAS,KAAK;EAC1D,MAAM,mBACJ,MACA,SACA,cAAc,WACd,oBAAoB,KAAK,GACzB,MAAM,IACN,EAAE,WAAW,IAAI,IAAI,SAAS,KAAK,aAAa,SAAS,MAAM,CAAC,EAAE,CACpE;EACA,MAAM,QAAQ,IACZ,SAAS,IAAI,OAAO,aAAa;GAC/B,MAAM,OAAO;IACX,GAAG,oBAAoB,KAAK;IAC5B,iBAAiB,iBAAiB,SAAS,UAAU;GACvD;GACA,MAAM,mBAAmB,MAAM,SAAS,SAAS,QAAQ,MAAM,WAAW,MAAM,IAAI;EACtF,CAAC,CACH;CACF;AACF;;AAGA,SAAS,aAAa,SAAmD;CACvE,MAAM,UAAU,QAAQ,SAAS;CACjC,OAAO,YAAY,KAAA,IAAY,CAAC,IAAI,EAAE,eAAe,QAAQ;AAC/D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyshelf/app",
|
|
3
|
-
"version": "0.10.0-next-
|
|
3
|
+
"version": "0.10.0-next-ccff478",
|
|
4
4
|
"description": "StoryShelf app: Hono app, API routes, and server-rendered UI over @storyshelf/core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chromatic-alternative",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"dependencies": {
|
|
62
62
|
"@hono/swagger-ui": "^0.6.1",
|
|
63
63
|
"@hono/zod-openapi": "^1.1.5",
|
|
64
|
-
"@storyshelf/core": "0.10.0-next-
|
|
65
|
-
"@storyshelf/observability": "0.10.0-next-
|
|
64
|
+
"@storyshelf/core": "0.10.0-next-ccff478",
|
|
65
|
+
"@storyshelf/observability": "0.10.0-next-ccff478",
|
|
66
66
|
"hono": "^4.11.0",
|
|
67
67
|
"zod": "^4.6.7"
|
|
68
68
|
},
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"@opentelemetry/core": "^2.11.0",
|
|
73
73
|
"@opentelemetry/sdk-trace-base": "^2.11.0",
|
|
74
74
|
"@storybook/html-vite": "10.6.5",
|
|
75
|
-
"@storyshelf/auth": "0.10.0-next-
|
|
76
|
-
"@storyshelf/db-sqlite": "0.10.0-next-
|
|
77
|
-
"@storyshelf/design-figma": "0.10.0-next-
|
|
75
|
+
"@storyshelf/auth": "0.10.0-next-ccff478",
|
|
76
|
+
"@storyshelf/db-sqlite": "0.10.0-next-ccff478",
|
|
77
|
+
"@storyshelf/design-figma": "0.10.0-next-ccff478",
|
|
78
78
|
"@types/node": "^26.0.0",
|
|
79
79
|
"@vitest/coverage-v8": "^4.0.0",
|
|
80
80
|
"adm-zip": "0.6.1",
|