@shipfox/api-runners 12.7.0 → 13.0.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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +12 -0
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/job-executions.d.ts +8 -24
- package/dist/db/job-executions.d.ts.map +1 -1
- package/dist/db/job-executions.js +62 -81
- package/dist/db/job-executions.js.map +1 -1
- package/dist/db/reservations.d.ts.map +1 -1
- package/dist/db/reservations.js +6 -4
- package/dist/db/reservations.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/presentation/index.d.ts +2 -1
- package/dist/presentation/index.d.ts.map +1 -1
- package/dist/presentation/index.js +2 -1
- package/dist/presentation/index.js.map +1 -1
- package/dist/presentation/inter-module.d.ts +0 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +2 -25
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/subscribers/on-workflows-job-execution-queued.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-queued.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-queued.js +21 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-queued.js.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-terminated.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-terminated.d.ts.map +1 -0
- package/dist/presentation/subscribers/{on-workflows-job-execution-timed-out.js → on-workflows-job-execution-terminated.js} +5 -4
- package/dist/presentation/subscribers/on-workflows-job-execution-terminated.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/index.ts +0 -2
- package/src/db/job-executions.test.ts +105 -335
- package/src/db/job-executions.ts +70 -91
- package/src/db/reservations.ts +6 -3
- package/src/db/runner-instances.test.ts +100 -0
- package/src/index.test.ts +1 -0
- package/src/index.ts +8 -7
- package/src/presentation/index.ts +2 -1
- package/src/presentation/inter-module.ts +2 -40
- package/src/presentation/subscribers/on-workflows-job-execution-queued.test.ts +57 -0
- package/src/presentation/subscribers/on-workflows-job-execution-queued.ts +26 -0
- package/src/presentation/subscribers/on-workflows-job-execution-terminated.test.ts +142 -0
- package/src/presentation/subscribers/{on-workflows-job-execution-timed-out.ts → on-workflows-job-execution-terminated.ts} +5 -4
- package/test/factories/pending-job.ts +3 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts +0 -3
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts.map +0 -1
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js.map +0 -1
- package/src/presentation/inter-module.test.ts +0 -15
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.test.ts +0 -163
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
$ shipfox-swc && shipfox-temporal-bundle dist/temporal/workflows/index.js
|
|
2
|
-
Successfully compiled:
|
|
3
|
-
2026-08-
|
|
2
|
+
Successfully compiled: 105 files with swc (500.52ms)
|
|
3
|
+
2026-08-14T18:57:08.640Z [INFO] asset workflow-bundle-0c3da2487e29e352d64e.js 3.17 MiB [emitted] [immutable] (name: main)
|
|
4
4
|
orphan modules 33.5 KiB [orphan] 21 modules
|
|
5
5
|
runtime modules 1.13 KiB 5 modules
|
|
6
6
|
modules by path ../../../node_modules/.pnpm/ 970 KiB 196 modules
|
|
@@ -14,6 +14,6 @@ optional modules 30 bytes [optional]
|
|
|
14
14
|
__temporal_custom_payload_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
15
15
|
__temporal_custom_failure_converter (ignored) 15 bytes [optional] [built] [code generated]
|
|
16
16
|
../../shared/node/temporal/dist/workflow-error-interceptor.js 1.21 KiB [built] [code generated]
|
|
17
|
-
webpack 5.107.2 compiled successfully in
|
|
18
|
-
2026-08-
|
|
17
|
+
webpack 5.107.2 compiled successfully in 6538 ms
|
|
18
|
+
2026-08-14T18:57:08.663Z [INFO] Workflow bundle created { size: '3.17MB' }
|
|
19
19
|
/home/runner/work/shipfox/shipfox/libs/api/runners/dist/temporal/workflows/index.js: 3326598 bytes
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @shipfox/api-runners
|
|
2
2
|
|
|
3
|
+
## 13.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- af6b31e: Expose ordered queued and terminal workflow job-execution facts, and release terminal runner reservations once no uncancelled lease remains.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [af6b31e]
|
|
12
|
+
- @shipfox/api-runners-dto@13.0.0
|
|
13
|
+
- @shipfox/api-workflows-dto@13.0.0
|
|
14
|
+
|
|
3
15
|
## 12.7.0
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/db/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { closeDb, db, schema } from './db.js';
|
|
|
4
4
|
export type { CreateEphemeralRegistrationTokenParams, DeleteExpiredEphemeralRegistrationTokensParams, } from './ephemeral-registration-tokens.js';
|
|
5
5
|
export { createEphemeralRegistrationToken, createRunnerSessionConsumingEphemeralToken, deleteExpiredEphemeralRegistrationTokens, resolveEphemeralRegistrationTokenByHash, } from './ephemeral-registration-tokens.js';
|
|
6
6
|
export type { ClaimedJobExecution, EnqueueJobExecutionParams, RunnerInstanceBoundJobExecution, } from './job-executions.js';
|
|
7
|
-
export {
|
|
7
|
+
export { claimPendingJobExecution, enqueueJobExecution, expireStuckJobExecutions, getWorkspaceJobCounts, isJobLeaseActive, listActiveRunningJobExecutions, listRunningJobExecutionsByRunnerInstanceTx, recordHeartbeat, } from './job-executions.js';
|
|
8
8
|
export type { CreateManualRegistrationTokenParams } from './manual-registration-tokens.js';
|
|
9
9
|
export { createManualRegistrationToken, listUsableManualRegistrationTokensByWorkspaceId, resolveManualRegistrationTokenByHash, revokeManualRegistrationToken, } from './manual-registration-tokens.js';
|
|
10
10
|
export { hasActiveWorkspaceProvisionerCapability, listActiveWorkspaceProvisionerCapabilitySnapshots, listStaleWorkspaceProvisionerCapabilitySnapshots, publishWorkspaceProvisionerCapabilitySnapshot, } from './provisioner-capability-snapshots.js';
|
package/dist/db/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,mCAAmC,EACnC,8BAA8B,EAC9B,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAC,gCAAgC,EAAC,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAC5C,YAAY,EACV,sCAAsC,EACtC,8CAA8C,GAC/C,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,gCAAgC,EAChC,0CAA0C,EAC1C,wCAAwC,EACxC,uCAAuC,GACxC,MAAM,oCAAoC,CAAC;AAC5C,YAAY,EACV,mBAAmB,EACnB,yBAAyB,EACzB,+BAA+B,GAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACV,mCAAmC,EACnC,8BAA8B,EAC9B,sCAAsC,EACtC,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAC,gCAAgC,EAAC,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAAC,OAAO,EAAE,EAAE,EAA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AY,EACV,iCAAiC,EACjC,8BAA8B,EAC9B,gCAAgC,EAChC,8BAA8B,EAC9B,2BAA2B,EAC3B,yBAAyB,EACzB,6BAA6B,EAC7B,mCAAmC,GACpC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,8BAA8B,EAC9B,iCAAiC,EACjC,eAAe,EACf,0CAA0C,EAC1C,yBAAyB,EACzB,oCAAoC,EACpC,+BAA+B,EAC/B,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,yBAAyB,EACzB,iCAAiC,GAClC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,mBAAmB,EAAE,2BAA2B,EAAC,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAC,aAAa,EAAC,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAC,qBAAqB,EAAE,qBAAqB,EAAC,MAAM,qCAAqC,CAAC;AAEjG,eAAO,MAAM,cAAc,QAAoE,CAAC"}
|
package/dist/db/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
export { listAdministratorRunnerInstances } from './admin-runner-instances.js';
|
|
4
4
|
export { closeDb, db, schema } from './db.js';
|
|
5
5
|
export { createEphemeralRegistrationToken, createRunnerSessionConsumingEphemeralToken, deleteExpiredEphemeralRegistrationTokens, resolveEphemeralRegistrationTokenByHash } from './ephemeral-registration-tokens.js';
|
|
6
|
-
export {
|
|
6
|
+
export { claimPendingJobExecution, enqueueJobExecution, expireStuckJobExecutions, getWorkspaceJobCounts, isJobLeaseActive, listActiveRunningJobExecutions, listRunningJobExecutionsByRunnerInstanceTx, recordHeartbeat } from './job-executions.js';
|
|
7
7
|
export { createManualRegistrationToken, listUsableManualRegistrationTokensByWorkspaceId, resolveManualRegistrationTokenByHash, revokeManualRegistrationToken } from './manual-registration-tokens.js';
|
|
8
8
|
export { hasActiveWorkspaceProvisionerCapability, listActiveWorkspaceProvisionerCapabilitySnapshots, listStaleWorkspaceProvisionerCapabilitySnapshots, publishWorkspaceProvisionerCapabilitySnapshot } from './provisioner-capability-snapshots.js';
|
|
9
9
|
export { createInstallationProvisionerTokenWithAudit, createProvisionerToken, listActiveProvisionerTokens, listInstallationProvisionerTokens, listUsableProvisionerTokensByWorkspaceId, resolveProvisionerTokenByHash, revokeInstallationProvisionerTokenWithAudit, revokeProvisionerToken, touchProvisionerLastSeen } from './provisioner-tokens.js';
|
package/dist/db/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/db/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nexport type {\n AdministratorRunnerAssignmentFilter,\n AdministratorRunnerInstanceRow,\n ListAdministratorRunnerInstancesParams,\n ListAdministratorRunnerInstancesResult,\n} from './admin-runner-instances.js';\nexport {listAdministratorRunnerInstances} from './admin-runner-instances.js';\nexport {closeDb, db, schema} from './db.js';\nexport type {\n CreateEphemeralRegistrationTokenParams,\n DeleteExpiredEphemeralRegistrationTokensParams,\n} from './ephemeral-registration-tokens.js';\nexport {\n createEphemeralRegistrationToken,\n createRunnerSessionConsumingEphemeralToken,\n deleteExpiredEphemeralRegistrationTokens,\n resolveEphemeralRegistrationTokenByHash,\n} from './ephemeral-registration-tokens.js';\nexport type {\n ClaimedJobExecution,\n EnqueueJobExecutionParams,\n RunnerInstanceBoundJobExecution,\n} from './job-executions.js';\nexport {\n
|
|
1
|
+
{"version":3,"sources":["../../src/db/index.ts"],"sourcesContent":["import {dirname, resolve} from 'node:path';\nimport {fileURLToPath} from 'node:url';\n\nexport type {\n AdministratorRunnerAssignmentFilter,\n AdministratorRunnerInstanceRow,\n ListAdministratorRunnerInstancesParams,\n ListAdministratorRunnerInstancesResult,\n} from './admin-runner-instances.js';\nexport {listAdministratorRunnerInstances} from './admin-runner-instances.js';\nexport {closeDb, db, schema} from './db.js';\nexport type {\n CreateEphemeralRegistrationTokenParams,\n DeleteExpiredEphemeralRegistrationTokensParams,\n} from './ephemeral-registration-tokens.js';\nexport {\n createEphemeralRegistrationToken,\n createRunnerSessionConsumingEphemeralToken,\n deleteExpiredEphemeralRegistrationTokens,\n resolveEphemeralRegistrationTokenByHash,\n} from './ephemeral-registration-tokens.js';\nexport type {\n ClaimedJobExecution,\n EnqueueJobExecutionParams,\n RunnerInstanceBoundJobExecution,\n} from './job-executions.js';\nexport {\n claimPendingJobExecution,\n enqueueJobExecution,\n expireStuckJobExecutions,\n getWorkspaceJobCounts,\n isJobLeaseActive,\n listActiveRunningJobExecutions,\n listRunningJobExecutionsByRunnerInstanceTx,\n recordHeartbeat,\n} from './job-executions.js';\nexport type {CreateManualRegistrationTokenParams} from './manual-registration-tokens.js';\nexport {\n createManualRegistrationToken,\n listUsableManualRegistrationTokensByWorkspaceId,\n resolveManualRegistrationTokenByHash,\n revokeManualRegistrationToken,\n} from './manual-registration-tokens.js';\nexport {\n hasActiveWorkspaceProvisionerCapability,\n listActiveWorkspaceProvisionerCapabilitySnapshots,\n listStaleWorkspaceProvisionerCapabilitySnapshots,\n publishWorkspaceProvisionerCapabilitySnapshot,\n} from './provisioner-capability-snapshots.js';\nexport type {CreateProvisionerTokenParams} from './provisioner-tokens.js';\nexport {\n createInstallationProvisionerTokenWithAudit,\n createProvisionerToken,\n listActiveProvisionerTokens,\n listInstallationProvisionerTokens,\n listUsableProvisionerTokensByWorkspaceId,\n resolveProvisionerTokenByHash,\n revokeInstallationProvisionerTokenWithAudit,\n revokeProvisionerToken,\n touchProvisionerLastSeen,\n} from './provisioner-tokens.js';\nexport {\n consumeRunnersRateLimit,\n pruneExpiredRunnersRateLimits,\n} from './rate-limits.js';\nexport type {\n DemandStat,\n PollDemandAndReserveParams,\n ReservationGrant,\n ReservationTemplate,\n} from './reservations.js';\nexport {\n deleteExpiredReservations,\n deleteReservationsByIds,\n pollDemandAndReserve,\n releaseReservationUnits,\n} from './reservations.js';\nexport {assignRunnerInstances} from './runner-assignments.js';\nexport type {\n ActiveRunnerInstanceTemplateCount,\n ReapStaleRunnerInstancesResult,\n ReconcileRunnerInstancesDbResult,\n ReconcileRunnerInstancesParams,\n ReportRunnerInstancesParams,\n RunnerInstanceReportEvent,\n RunnerInstanceTerminateIntent,\n RunnerInstanceTerminateIntentReason,\n} from './runner-instances.js';\nexport {\n attachRunnerInstanceProviderId,\n countStaleEnrolledRunnerInstances,\n isTerminalState,\n listActiveRunnerInstanceCountsByTemplateTx,\n listActiveRunnerInstances,\n listProvisionerTerminateIntentRowsTx,\n listProvisionerTerminateIntents,\n reapStaleRunnerInstances,\n reconcileRunnerInstances,\n reportRunnerInstances,\n} from './runner-instances.js';\nexport type {\n CreateRunnerSessionParams,\n DeleteExpiredRunnerSessionsParams,\n} from './runner-sessions.js';\nexport {createRunnerSession, deleteExpiredRunnerSessions} from './runner-sessions.js';\nexport {runnersOutbox} from './schema/outbox.js';\nexport {runnerBootstrapTokens, runnerControlSessions} from './schema/runner-control-sessions.js';\n\nexport const migrationsPath = resolve(dirname(fileURLToPath(import.meta.url)), '../../drizzle');\n"],"names":["dirname","resolve","fileURLToPath","listAdministratorRunnerInstances","closeDb","db","schema","createEphemeralRegistrationToken","createRunnerSessionConsumingEphemeralToken","deleteExpiredEphemeralRegistrationTokens","resolveEphemeralRegistrationTokenByHash","claimPendingJobExecution","enqueueJobExecution","expireStuckJobExecutions","getWorkspaceJobCounts","isJobLeaseActive","listActiveRunningJobExecutions","listRunningJobExecutionsByRunnerInstanceTx","recordHeartbeat","createManualRegistrationToken","listUsableManualRegistrationTokensByWorkspaceId","resolveManualRegistrationTokenByHash","revokeManualRegistrationToken","hasActiveWorkspaceProvisionerCapability","listActiveWorkspaceProvisionerCapabilitySnapshots","listStaleWorkspaceProvisionerCapabilitySnapshots","publishWorkspaceProvisionerCapabilitySnapshot","createInstallationProvisionerTokenWithAudit","createProvisionerToken","listActiveProvisionerTokens","listInstallationProvisionerTokens","listUsableProvisionerTokensByWorkspaceId","resolveProvisionerTokenByHash","revokeInstallationProvisionerTokenWithAudit","revokeProvisionerToken","touchProvisionerLastSeen","consumeRunnersRateLimit","pruneExpiredRunnersRateLimits","deleteExpiredReservations","deleteReservationsByIds","pollDemandAndReserve","releaseReservationUnits","assignRunnerInstances","attachRunnerInstanceProviderId","countStaleEnrolledRunnerInstances","isTerminalState","listActiveRunnerInstanceCountsByTemplateTx","listActiveRunnerInstances","listProvisionerTerminateIntentRowsTx","listProvisionerTerminateIntents","reapStaleRunnerInstances","reconcileRunnerInstances","reportRunnerInstances","createRunnerSession","deleteExpiredRunnerSessions","runnersOutbox","runnerBootstrapTokens","runnerControlSessions","migrationsPath","url"],"mappings":"AAAA,SAAQA,OAAO,EAAEC,OAAO,QAAO,YAAY;AAC3C,SAAQC,aAAa,QAAO,WAAW;AAQvC,SAAQC,gCAAgC,QAAO,8BAA8B;AAC7E,SAAQC,OAAO,EAAEC,EAAE,EAAEC,MAAM,QAAO,UAAU;AAK5C,SACEC,gCAAgC,EAChCC,0CAA0C,EAC1CC,wCAAwC,EACxCC,uCAAuC,QAClC,qCAAqC;AAM5C,SACEC,wBAAwB,EACxBC,mBAAmB,EACnBC,wBAAwB,EACxBC,qBAAqB,EACrBC,gBAAgB,EAChBC,8BAA8B,EAC9BC,0CAA0C,EAC1CC,eAAe,QACV,sBAAsB;AAE7B,SACEC,6BAA6B,EAC7BC,+CAA+C,EAC/CC,oCAAoC,EACpCC,6BAA6B,QACxB,kCAAkC;AACzC,SACEC,uCAAuC,EACvCC,iDAAiD,EACjDC,gDAAgD,EAChDC,6CAA6C,QACxC,wCAAwC;AAE/C,SACEC,2CAA2C,EAC3CC,sBAAsB,EACtBC,2BAA2B,EAC3BC,iCAAiC,EACjCC,wCAAwC,EACxCC,6BAA6B,EAC7BC,2CAA2C,EAC3CC,sBAAsB,EACtBC,wBAAwB,QACnB,0BAA0B;AACjC,SACEC,uBAAuB,EACvBC,6BAA6B,QACxB,mBAAmB;AAO1B,SACEC,yBAAyB,EACzBC,uBAAuB,EACvBC,oBAAoB,EACpBC,uBAAuB,QAClB,oBAAoB;AAC3B,SAAQC,qBAAqB,QAAO,0BAA0B;AAW9D,SACEC,8BAA8B,EAC9BC,iCAAiC,EACjCC,eAAe,EACfC,0CAA0C,EAC1CC,yBAAyB,EACzBC,oCAAoC,EACpCC,+BAA+B,EAC/BC,wBAAwB,EACxBC,wBAAwB,EACxBC,qBAAqB,QAChB,wBAAwB;AAK/B,SAAQC,mBAAmB,EAAEC,2BAA2B,QAAO,uBAAuB;AACtF,SAAQC,aAAa,QAAO,qBAAqB;AACjD,SAAQC,qBAAqB,EAAEC,qBAAqB,QAAO,sCAAsC;AAEjG,OAAO,MAAMC,iBAAiBzD,QAAQD,QAAQE,cAAc,YAAYyD,GAAG,IAAI,iBAAiB"}
|
|
@@ -8,6 +8,7 @@ export interface EnqueueJobExecutionParams {
|
|
|
8
8
|
jobExecutionId: string;
|
|
9
9
|
projectId: string;
|
|
10
10
|
requiredLabels: string[];
|
|
11
|
+
queuedAt: Date;
|
|
11
12
|
}
|
|
12
13
|
export declare function getWorkspaceJobCounts(params: {
|
|
13
14
|
workspaceIds: string[];
|
|
@@ -55,32 +56,18 @@ export declare function claimPendingJobExecution(params: {
|
|
|
55
56
|
maxClaims: number | null;
|
|
56
57
|
runnerSessionLivenessThrottleSeconds: number;
|
|
57
58
|
}): Promise<ClaimedJobExecution | null>;
|
|
58
|
-
/**
|
|
59
|
-
* Releases a job execution's lease when the orchestration workflow finalizes it: deletes the
|
|
60
|
-
* running-job-execution row AND any lingering pending row for the same execution, in one tx.
|
|
61
|
-
* When the deleted lease was the last one for a terminal provider runner, it also releases the
|
|
62
|
-
* runner's reservation in the same runner-owned transaction. Terminal reports and workflow lease
|
|
63
|
-
* finalization remain independently retryable; they do not share a cross-module scope lock.
|
|
64
|
-
* Idempotent (0-row no-op), no token scope (the workflow is authoritative), and
|
|
65
|
-
* emits no event: the workflow already owns the outcome. Sweeping the pending row
|
|
66
|
-
* too closes the at-least-once window where an enqueue retry left an orphan that a
|
|
67
|
-
* later claim would otherwise pick up for an already-finished job execution.
|
|
68
|
-
*/
|
|
69
|
-
export declare function releaseJobExecution(params: {
|
|
70
|
-
jobExecutionId: string;
|
|
71
|
-
}): Promise<void>;
|
|
72
59
|
/**
|
|
73
60
|
* Reaps stale leases (bounded by `limit`), emitting one
|
|
74
61
|
* `runners.job.lease_expired` event per reaped job execution.
|
|
75
62
|
*
|
|
76
63
|
* The cutoff is re-checked in the DELETE, not just the locking subquery, so a
|
|
77
64
|
* heartbeat landing mid-call spares the live row. Each reaped execution also sweeps its
|
|
78
|
-
* pending row
|
|
79
|
-
* that a later claim re-runs as an already-finished job execution.
|
|
65
|
+
* pending row so an at-least-once queue replay cannot leave an orphan.
|
|
80
66
|
*
|
|
81
|
-
* Locks pending-then-running to match `claimPendingJobExecution
|
|
82
|
-
* `reconcileTerminalJobExecution`. The stale candidate scan intentionally does not lock
|
|
83
|
-
* rows first; the running-row DELETE re-checks the stale predicate after the
|
|
67
|
+
* Locks pending-then-running to match `claimPendingJobExecution` and
|
|
68
|
+
* `reconcileTerminalJobExecution`. The stale candidate scan intentionally does not lock
|
|
69
|
+
* running rows first; the running-row DELETE re-checks the stale predicate after the
|
|
70
|
+
* pending-row sweep.
|
|
84
71
|
*/
|
|
85
72
|
export declare function expireStuckJobExecutions(params: {
|
|
86
73
|
thresholdSeconds: number;
|
|
@@ -131,13 +118,10 @@ export declare function recordHeartbeat(params: {
|
|
|
131
118
|
}>;
|
|
132
119
|
/**
|
|
133
120
|
* Reconciles a terminal job execution with runner state in one transaction: removes its pending
|
|
134
|
-
* queue row
|
|
135
|
-
* idempotent and preserves the first cancellation-request timestamp.
|
|
121
|
+
* queue row, requests cancellation on its running lease, and converges any linked reservation.
|
|
122
|
+
* The operation is idempotent and preserves the first cancellation-request timestamp.
|
|
136
123
|
*/
|
|
137
124
|
export declare function reconcileTerminalJobExecution(params: {
|
|
138
125
|
jobExecutionId: string;
|
|
139
126
|
}): Promise<void>;
|
|
140
|
-
export declare function cancelRunnerJobs(params: {
|
|
141
|
-
jobIds: string[];
|
|
142
|
-
}): Promise<void>;
|
|
143
127
|
//# sourceMappingURL=job-executions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-executions.d.ts","sourceRoot":"","sources":["../../src/db/job-executions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"job-executions.d.ts","sourceRoot":"","sources":["../../src/db/job-executions.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,yBAAyB,EAC/B,MAAM,0BAA0B,CAAC;AAiClC,OAAO,KAAK,EAAC,EAAE,EAAC,MAAM,SAAS,CAAC;AAkDhC,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,QAAQ,EAAE,IAAI,CAAC;CAChB;AAED,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB,GAAG,OAAO,CAAC,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC,CAwBzE;AAKD,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C1F;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC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EAAE,MAAM,CAAC;QACd,cAAc,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC,CAoED;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CAAC,MAAM,EAAE;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RUNNER_JOB_CLAIMED, RUNNER_JOB_LEASE_EXPIRED
|
|
1
|
+
import { RUNNER_JOB_CLAIMED, RUNNER_JOB_LEASE_EXPIRED } from '@shipfox/api-runners-dto';
|
|
2
2
|
import { logger } from '@shipfox/node-opentelemetry';
|
|
3
3
|
import { writeOutboxEvent, writeOutboxEvents } from '@shipfox/node-outbox';
|
|
4
4
|
import { canonicalizeLabels } from '@shipfox/runner-labels';
|
|
@@ -16,6 +16,34 @@ const runnerJobExecutionLockPrefix = 'runners_job_execution:';
|
|
|
16
16
|
async function lockJobExecution(tx, jobExecutionId) {
|
|
17
17
|
await tx.execute(sql`select pg_advisory_xact_lock(hashtext(${`${runnerJobExecutionLockPrefix}${jobExecutionId}`}))`);
|
|
18
18
|
}
|
|
19
|
+
async function releaseReservationsForTerminalRunningRows(tx, rows) {
|
|
20
|
+
// Converge after the lease fact changes. The reservation helper locks each provider runner
|
|
21
|
+
// and releases only when the runner is terminal and no uncancelled lease remains.
|
|
22
|
+
const providerRunnerIdsByProvisionerId = new Map();
|
|
23
|
+
for (const row of rows){
|
|
24
|
+
if (row.provisionerId === null || row.providerRunnerId === null) continue;
|
|
25
|
+
const providerRunnerIds = providerRunnerIdsByProvisionerId.get(row.provisionerId) ?? new Set();
|
|
26
|
+
providerRunnerIds.add(row.providerRunnerId);
|
|
27
|
+
providerRunnerIdsByProvisionerId.set(row.provisionerId, providerRunnerIds);
|
|
28
|
+
}
|
|
29
|
+
for (const provisionerId of [
|
|
30
|
+
...providerRunnerIdsByProvisionerId.keys()
|
|
31
|
+
].sort()){
|
|
32
|
+
const providerRunnerIds = providerRunnerIdsByProvisionerId.get(provisionerId);
|
|
33
|
+
if (!providerRunnerIds) continue;
|
|
34
|
+
await releaseTerminalRunnerInstanceReservationsByIds(tx, {
|
|
35
|
+
workspaceId: null,
|
|
36
|
+
provisionerId,
|
|
37
|
+
providerRunnerIds: [
|
|
38
|
+
...providerRunnerIds
|
|
39
|
+
].sort(),
|
|
40
|
+
requireUnlinkedSession: false,
|
|
41
|
+
// Lock and re-check the runner row locally so lease finalization remains retryable
|
|
42
|
+
// without a workflow/runner scope lock.
|
|
43
|
+
requireTerminalState: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
19
47
|
export async function getWorkspaceJobCounts(params) {
|
|
20
48
|
const [pendingRows, runningRows] = await Promise.all([
|
|
21
49
|
db().select({
|
|
@@ -41,11 +69,9 @@ export async function getWorkspaceJobCounts(params) {
|
|
|
41
69
|
running: runningByWorkspace.get(workspaceId) ?? 0
|
|
42
70
|
}));
|
|
43
71
|
}
|
|
44
|
-
//
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
// The per-execution advisory lock serializes retries with lease expiry/reconciliation, and the
|
|
48
|
-
// durable lease-expired event prevents a retry from re-queueing an execution already reaped.
|
|
72
|
+
// The workflows outbox delivers queue facts at least once. The per-execution advisory lock and
|
|
73
|
+
// pending/running checks make replay a no-op across the claim transition. A durable lease-expired
|
|
74
|
+
// event also prevents a delayed replay from resurrecting an execution already reaped locally.
|
|
49
75
|
export async function enqueueJobExecution(params) {
|
|
50
76
|
const requiredLabels = [
|
|
51
77
|
...canonicalizeLabels(params.requiredLabels)
|
|
@@ -53,6 +79,10 @@ export async function enqueueJobExecution(params) {
|
|
|
53
79
|
if (requiredLabels.length === 0) throw new EmptyRequiredLabelsError();
|
|
54
80
|
const enqueued = await db().transaction(async (tx)=>{
|
|
55
81
|
await lockJobExecution(tx, params.jobExecutionId);
|
|
82
|
+
const [running] = await tx.select({
|
|
83
|
+
jobExecutionId: runningJobExecutions.jobExecutionId
|
|
84
|
+
}).from(runningJobExecutions).where(eq(runningJobExecutions.jobExecutionId, params.jobExecutionId)).limit(1);
|
|
85
|
+
if (running) return false;
|
|
56
86
|
const [leaseExpired] = await tx.select({
|
|
57
87
|
id: runnersOutbox.id
|
|
58
88
|
}).from(runnersOutbox).where(and(eq(runnersOutbox.eventType, RUNNER_JOB_LEASE_EXPIRED), sql`${runnersOutbox.payload}->>'jobExecutionId' = ${params.jobExecutionId}`)).limit(1);
|
|
@@ -64,27 +94,14 @@ export async function enqueueJobExecution(params) {
|
|
|
64
94
|
jobId: params.jobId,
|
|
65
95
|
jobExecutionId: params.jobExecutionId,
|
|
66
96
|
projectId: params.projectId,
|
|
67
|
-
requiredLabels
|
|
97
|
+
requiredLabels,
|
|
98
|
+
createdAt: params.queuedAt
|
|
68
99
|
}).onConflictDoNothing({
|
|
69
100
|
target: pendingJobExecutions.jobExecutionId
|
|
70
101
|
}).returning({
|
|
71
102
|
createdAt: pendingJobExecutions.createdAt
|
|
72
103
|
});
|
|
73
|
-
|
|
74
|
-
// emitted the queued event (durably, in the outbox), so re-emitting would
|
|
75
|
-
// only add a redundant row the subscriber coalesces away. Skip it.
|
|
76
|
-
if (!inserted) return false;
|
|
77
|
-
await writeOutboxEvent(tx, runnersOutbox, {
|
|
78
|
-
type: RUNNER_JOB_QUEUED,
|
|
79
|
-
payload: {
|
|
80
|
-
workflowRunId: params.workflowRunId,
|
|
81
|
-
workflowRunAttemptId: params.workflowRunAttemptId,
|
|
82
|
-
jobId: params.jobId,
|
|
83
|
-
jobExecutionId: params.jobExecutionId,
|
|
84
|
-
queuedAt: inserted.createdAt.toISOString()
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return true;
|
|
104
|
+
return inserted !== undefined;
|
|
88
105
|
});
|
|
89
106
|
if (enqueued) jobExecutionEnqueuedCount.add(1);
|
|
90
107
|
}
|
|
@@ -227,57 +244,18 @@ async function touchRunnerSessionLiveness(params) {
|
|
|
227
244
|
updatedAt: sql`now()`
|
|
228
245
|
}).where(and(eq(runnerSessions.id, params.runnerSessionId), eq(runnerSessions.workspaceId, params.workspaceId), sql`${runnerSessions.updatedAt} < now() - (${params.throttleSeconds} || ' seconds')::interval`));
|
|
229
246
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Releases a job execution's lease when the orchestration workflow finalizes it: deletes the
|
|
232
|
-
* running-job-execution row AND any lingering pending row for the same execution, in one tx.
|
|
233
|
-
* When the deleted lease was the last one for a terminal provider runner, it also releases the
|
|
234
|
-
* runner's reservation in the same runner-owned transaction. Terminal reports and workflow lease
|
|
235
|
-
* finalization remain independently retryable; they do not share a cross-module scope lock.
|
|
236
|
-
* Idempotent (0-row no-op), no token scope (the workflow is authoritative), and
|
|
237
|
-
* emits no event: the workflow already owns the outcome. Sweeping the pending row
|
|
238
|
-
* too closes the at-least-once window where an enqueue retry left an orphan that a
|
|
239
|
-
* later claim would otherwise pick up for an already-finished job execution.
|
|
240
|
-
*/ export async function releaseJobExecution(params) {
|
|
241
|
-
await db().transaction(async (tx)=>{
|
|
242
|
-
await lockJobExecution(tx, params.jobExecutionId);
|
|
243
|
-
// Delete pending before running to match `claimPendingJobExecution`'s lock-acquisition
|
|
244
|
-
// order (it locks the pending row first, then the running row). A concurrent
|
|
245
|
-
// claim picking up an orphan pending row for this same job execution would otherwise
|
|
246
|
-
// deadlock against the reverse order here.
|
|
247
|
-
await tx.delete(pendingJobExecutions).where(eq(pendingJobExecutions.jobExecutionId, params.jobExecutionId));
|
|
248
|
-
const deletedRunningRows = await tx.delete(runningJobExecutions).where(eq(runningJobExecutions.jobExecutionId, params.jobExecutionId)).returning({
|
|
249
|
-
workspaceId: runningJobExecutions.workspaceId,
|
|
250
|
-
provisionerId: runningJobExecutions.provisionerId,
|
|
251
|
-
providerRunnerId: runningJobExecutions.providerRunnerId
|
|
252
|
-
});
|
|
253
|
-
const deletedRunningRow = deletedRunningRows[0];
|
|
254
|
-
if (deletedRunningRow?.provisionerId && deletedRunningRow.providerRunnerId) {
|
|
255
|
-
await releaseTerminalRunnerInstanceReservationsByIds(tx, {
|
|
256
|
-
workspaceId: null,
|
|
257
|
-
provisionerId: deletedRunningRow.provisionerId,
|
|
258
|
-
providerRunnerIds: [
|
|
259
|
-
deletedRunningRow.providerRunnerId
|
|
260
|
-
],
|
|
261
|
-
requireUnlinkedSession: false,
|
|
262
|
-
// Lock and re-check the runner row locally so terminal reporting remains retryable
|
|
263
|
-
// without a workflow/runner scope lock.
|
|
264
|
-
requireTerminalState: false
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
247
|
/**
|
|
270
248
|
* Reaps stale leases (bounded by `limit`), emitting one
|
|
271
249
|
* `runners.job.lease_expired` event per reaped job execution.
|
|
272
250
|
*
|
|
273
251
|
* The cutoff is re-checked in the DELETE, not just the locking subquery, so a
|
|
274
252
|
* heartbeat landing mid-call spares the live row. Each reaped execution also sweeps its
|
|
275
|
-
* pending row
|
|
276
|
-
* that a later claim re-runs as an already-finished job execution.
|
|
253
|
+
* pending row so an at-least-once queue replay cannot leave an orphan.
|
|
277
254
|
*
|
|
278
|
-
* Locks pending-then-running to match `claimPendingJobExecution
|
|
279
|
-
* `reconcileTerminalJobExecution`. The stale candidate scan intentionally does not lock
|
|
280
|
-
* rows first; the running-row DELETE re-checks the stale predicate after the
|
|
255
|
+
* Locks pending-then-running to match `claimPendingJobExecution` and
|
|
256
|
+
* `reconcileTerminalJobExecution`. The stale candidate scan intentionally does not lock
|
|
257
|
+
* running rows first; the running-row DELETE re-checks the stale predicate after the
|
|
258
|
+
* pending-row sweep.
|
|
281
259
|
*/ export async function expireStuckJobExecutions(params) {
|
|
282
260
|
const reaped = await db().transaction(async (tx)=>{
|
|
283
261
|
const heartbeatCutoff = sql`now() - (${params.thresholdSeconds} || ' seconds')::interval`;
|
|
@@ -303,9 +281,12 @@ async function touchRunnerSessionLiveness(params) {
|
|
|
303
281
|
workflowRunId: runningJobExecutions.workflowRunId,
|
|
304
282
|
workflowRunAttemptId: runningJobExecutions.workflowRunAttemptId,
|
|
305
283
|
jobId: runningJobExecutions.jobId,
|
|
306
|
-
jobExecutionId: runningJobExecutions.jobExecutionId
|
|
284
|
+
jobExecutionId: runningJobExecutions.jobExecutionId,
|
|
285
|
+
provisionerId: runningJobExecutions.provisionerId,
|
|
286
|
+
providerRunnerId: runningJobExecutions.providerRunnerId
|
|
307
287
|
});
|
|
308
288
|
if (deleted.length === 0) return [];
|
|
289
|
+
await releaseReservationsForTerminalRunningRows(tx, deleted);
|
|
309
290
|
await writeOutboxEvents(tx, runnersOutbox, deleted.map((row)=>({
|
|
310
291
|
type: RUNNER_JOB_LEASE_EXPIRED,
|
|
311
292
|
payload: {
|
|
@@ -315,7 +296,12 @@ async function touchRunnerSessionLiveness(params) {
|
|
|
315
296
|
jobExecutionId: row.jobExecutionId
|
|
316
297
|
}
|
|
317
298
|
})));
|
|
318
|
-
return deleted
|
|
299
|
+
return deleted.map(({ workflowRunId, workflowRunAttemptId, jobId, jobExecutionId })=>({
|
|
300
|
+
workflowRunId,
|
|
301
|
+
workflowRunAttemptId,
|
|
302
|
+
jobId,
|
|
303
|
+
jobExecutionId
|
|
304
|
+
}));
|
|
319
305
|
});
|
|
320
306
|
if (reaped.length > 0) jobExecutionLeaseExpiredCount.add(reaped.length);
|
|
321
307
|
return reaped;
|
|
@@ -453,8 +439,8 @@ export async function recordHeartbeat(params) {
|
|
|
453
439
|
}
|
|
454
440
|
/**
|
|
455
441
|
* Reconciles a terminal job execution with runner state in one transaction: removes its pending
|
|
456
|
-
* queue row
|
|
457
|
-
* idempotent and preserves the first cancellation-request timestamp.
|
|
442
|
+
* queue row, requests cancellation on its running lease, and converges any linked reservation.
|
|
443
|
+
* The operation is idempotent and preserves the first cancellation-request timestamp.
|
|
458
444
|
*/ export async function reconcileTerminalJobExecution(params) {
|
|
459
445
|
await db().transaction(async (tx)=>{
|
|
460
446
|
await lockJobExecution(tx, params.jobExecutionId);
|
|
@@ -462,18 +448,13 @@ export async function recordHeartbeat(params) {
|
|
|
462
448
|
// pending rows with SKIP LOCKED before inserting the running lease, so this ordering makes
|
|
463
449
|
// a concurrent terminal reconciliation either win before claim or cancel the new lease.
|
|
464
450
|
await tx.delete(pendingJobExecutions).where(eq(pendingJobExecutions.jobExecutionId, params.jobExecutionId));
|
|
465
|
-
await tx.update(runningJobExecutions).set({
|
|
466
|
-
cancellationRequestedAt: sql`COALESCE(${runningJobExecutions.cancellationRequestedAt}, now())`
|
|
467
|
-
}).where(eq(runningJobExecutions.jobExecutionId, params.jobExecutionId));
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
export async function cancelRunnerJobs(params) {
|
|
471
|
-
if (params.jobIds.length === 0) return;
|
|
472
|
-
await db().transaction(async (tx)=>{
|
|
473
|
-
await tx.delete(pendingJobExecutions).where(inArray(pendingJobExecutions.jobId, params.jobIds));
|
|
474
|
-
await tx.update(runningJobExecutions).set({
|
|
451
|
+
const cancelledRunningRows = await tx.update(runningJobExecutions).set({
|
|
475
452
|
cancellationRequestedAt: sql`COALESCE(${runningJobExecutions.cancellationRequestedAt}, now())`
|
|
476
|
-
}).where(
|
|
453
|
+
}).where(eq(runningJobExecutions.jobExecutionId, params.jobExecutionId)).returning({
|
|
454
|
+
provisionerId: runningJobExecutions.provisionerId,
|
|
455
|
+
providerRunnerId: runningJobExecutions.providerRunnerId
|
|
456
|
+
});
|
|
457
|
+
await releaseReservationsForTerminalRunningRows(tx, cancelledRunningRows);
|
|
477
458
|
});
|
|
478
459
|
}
|
|
479
460
|
|