@shipfox/api-runners 2.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 +2 -0
- package/.turbo/turbo-type$colon$emit.log +1 -0
- package/.turbo/turbo-type.log +1 -0
- package/CHANGELOG.md +187 -0
- package/LICENSE +21 -0
- package/dist/config.d.ts +30 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +208 -0
- package/dist/config.js.map +1 -0
- package/dist/core/demand.d.ts +33 -0
- package/dist/core/demand.d.ts.map +1 -0
- package/dist/core/demand.js +169 -0
- package/dist/core/demand.js.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts +14 -0
- package/dist/core/entities/ephemeral-registration-token.d.ts.map +1 -0
- package/dist/core/entities/ephemeral-registration-token.js +3 -0
- package/dist/core/entities/ephemeral-registration-token.js.map +1 -0
- package/dist/core/entities/manual-registration-token.d.ts +12 -0
- package/dist/core/entities/manual-registration-token.d.ts.map +1 -0
- package/dist/core/entities/manual-registration-token.js +3 -0
- package/dist/core/entities/manual-registration-token.js.map +1 -0
- package/dist/core/entities/provisioned-runner.d.ts +24 -0
- package/dist/core/entities/provisioned-runner.d.ts.map +1 -0
- package/dist/core/entities/provisioned-runner.js +3 -0
- package/dist/core/entities/provisioned-runner.js.map +1 -0
- package/dist/core/entities/provisioner-token.d.ts +18 -0
- package/dist/core/entities/provisioner-token.d.ts.map +1 -0
- package/dist/core/entities/provisioner-token.js +3 -0
- package/dist/core/entities/provisioner-token.js.map +1 -0
- package/dist/core/entities/reservation.d.ts +10 -0
- package/dist/core/entities/reservation.d.ts.map +1 -0
- package/dist/core/entities/reservation.js +3 -0
- package/dist/core/entities/reservation.js.map +1 -0
- package/dist/core/entities/runner-session.d.ts +18 -0
- package/dist/core/entities/runner-session.d.ts.map +1 -0
- package/dist/core/entities/runner-session.js +3 -0
- package/dist/core/entities/runner-session.js.map +1 -0
- package/dist/core/ephemeral-registration-tokens.d.ts +31 -0
- package/dist/core/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/core/ephemeral-registration-tokens.js +61 -0
- package/dist/core/ephemeral-registration-tokens.js.map +1 -0
- package/dist/core/errors.d.ts +62 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +92 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/index.d.ts +14 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/job-executions.d.ts +14 -0
- package/dist/core/job-executions.d.ts.map +1 -0
- package/dist/core/job-executions.js +37 -0
- package/dist/core/job-executions.js.map +1 -0
- package/dist/core/maintenance-policy.d.ts +2 -0
- package/dist/core/maintenance-policy.d.ts.map +1 -0
- package/dist/core/maintenance-policy.js +3 -0
- package/dist/core/maintenance-policy.js.map +1 -0
- package/dist/core/maintenance.d.ts +33 -0
- package/dist/core/maintenance.d.ts.map +1 -0
- package/dist/core/maintenance.js +55 -0
- package/dist/core/maintenance.js.map +1 -0
- package/dist/core/manual-registration-tokens.d.ts +17 -0
- package/dist/core/manual-registration-tokens.d.ts.map +1 -0
- package/dist/core/manual-registration-tokens.js +28 -0
- package/dist/core/manual-registration-tokens.js.map +1 -0
- package/dist/core/provisioned-runners.d.ts +67 -0
- package/dist/core/provisioned-runners.d.ts.map +1 -0
- package/dist/core/provisioned-runners.js +162 -0
- package/dist/core/provisioned-runners.js.map +1 -0
- package/dist/core/provisioner-tokens.d.ts +20 -0
- package/dist/core/provisioner-tokens.d.ts.map +1 -0
- package/dist/core/provisioner-tokens.js +36 -0
- package/dist/core/provisioner-tokens.js.map +1 -0
- package/dist/core/rate-limit.d.ts +35 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/rate-limit.js +74 -0
- package/dist/core/rate-limit.js.map +1 -0
- package/dist/core/runner-sessions.d.ts +26 -0
- package/dist/core/runner-sessions.d.ts.map +1 -0
- package/dist/core/runner-sessions.js +41 -0
- package/dist/core/runner-sessions.js.map +1 -0
- package/dist/core/runner-tool-capabilities.d.ts +24 -0
- package/dist/core/runner-tool-capabilities.d.ts.map +1 -0
- package/dist/core/runner-tool-capabilities.js +43 -0
- package/dist/core/runner-tool-capabilities.js.map +1 -0
- package/dist/db/db.d.ts +4478 -0
- package/dist/db/db.d.ts.map +1 -0
- package/dist/db/db.js +36 -0
- package/dist/db/db.js.map +1 -0
- package/dist/db/ephemeral-registration-tokens.d.ts +47 -0
- package/dist/db/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/ephemeral-registration-tokens.js +170 -0
- package/dist/db/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/index.d.ts +19 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +15 -0
- package/dist/db/index.js.map +1 -0
- package/dist/db/job-executions.d.ts +128 -0
- package/dist/db/job-executions.d.ts.map +1 -0
- package/dist/db/job-executions.js +354 -0
- package/dist/db/job-executions.js.map +1 -0
- package/dist/db/manual-registration-tokens.d.ts +16 -0
- package/dist/db/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/manual-registration-tokens.js +37 -0
- package/dist/db/manual-registration-tokens.js.map +1 -0
- package/dist/db/provisioned-runners.d.ts +79 -0
- package/dist/db/provisioned-runners.d.ts.map +1 -0
- package/dist/db/provisioned-runners.js +466 -0
- package/dist/db/provisioned-runners.js.map +1 -0
- package/dist/db/provisioner-tokens.d.ts +26 -0
- package/dist/db/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/provisioner-tokens.js +54 -0
- package/dist/db/provisioner-tokens.js.map +1 -0
- package/dist/db/rate-limits.d.ts +18 -0
- package/dist/db/rate-limits.d.ts.map +1 -0
- package/dist/db/rate-limits.js +44 -0
- package/dist/db/rate-limits.js.map +1 -0
- package/dist/db/reservations.d.ts +48 -0
- package/dist/db/reservations.d.ts.map +1 -0
- package/dist/db/reservations.js +162 -0
- package/dist/db/reservations.js.map +1 -0
- package/dist/db/runner-sessions.d.ts +18 -0
- package/dist/db/runner-sessions.d.ts.map +1 -0
- package/dist/db/runner-sessions.js +38 -0
- package/dist/db/runner-sessions.js.map +1 -0
- package/dist/db/schema/common.d.ts +2 -0
- package/dist/db/schema/common.d.ts.map +1 -0
- package/dist/db/schema/common.js +4 -0
- package/dist/db/schema/common.js.map +1 -0
- package/dist/db/schema/ephemeral-registration-tokens.d.ts +199 -0
- package/dist/db/schema/ephemeral-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/ephemeral-registration-tokens.js +45 -0
- package/dist/db/schema/ephemeral-registration-tokens.js.map +1 -0
- package/dist/db/schema/manual-registration-tokens.d.ts +165 -0
- package/dist/db/schema/manual-registration-tokens.d.ts.map +1 -0
- package/dist/db/schema/manual-registration-tokens.js +40 -0
- package/dist/db/schema/manual-registration-tokens.js.map +1 -0
- package/dist/db/schema/outbox.d.ts +195 -0
- package/dist/db/schema/outbox.d.ts.map +1 -0
- package/dist/db/schema/outbox.js +5 -0
- package/dist/db/schema/outbox.js.map +1 -0
- package/dist/db/schema/pending-job-executions.d.ts +189 -0
- package/dist/db/schema/pending-job-executions.d.ts.map +1 -0
- package/dist/db/schema/pending-job-executions.js +21 -0
- package/dist/db/schema/pending-job-executions.js.map +1 -0
- package/dist/db/schema/provisioned-runners.d.ts +379 -0
- package/dist/db/schema/provisioned-runners.d.ts.map +1 -0
- package/dist/db/schema/provisioned-runners.js +83 -0
- package/dist/db/schema/provisioned-runners.js.map +1 -0
- package/dist/db/schema/provisioner-tokens.d.ts +216 -0
- package/dist/db/schema/provisioner-tokens.d.ts.map +1 -0
- package/dist/db/schema/provisioner-tokens.js +48 -0
- package/dist/db/schema/provisioner-tokens.js.map +1 -0
- package/dist/db/schema/rate-limits.d.ts +145 -0
- package/dist/db/schema/rate-limits.d.ts.map +1 -0
- package/dist/db/schema/rate-limits.js +25 -0
- package/dist/db/schema/rate-limits.js.map +1 -0
- package/dist/db/schema/reservations.d.ts +157 -0
- package/dist/db/schema/reservations.d.ts.map +1 -0
- package/dist/db/schema/reservations.js +34 -0
- package/dist/db/schema/reservations.js.map +1 -0
- package/dist/db/schema/runner-sessions.d.ts +298 -0
- package/dist/db/schema/runner-sessions.d.ts.map +1 -0
- package/dist/db/schema/runner-sessions.js +61 -0
- package/dist/db/schema/runner-sessions.js.map +1 -0
- package/dist/db/schema/running-job-executions.d.ts +334 -0
- package/dist/db/schema/running-job-executions.d.ts.map +1 -0
- package/dist/db/schema/running-job-executions.js +41 -0
- package/dist/db/schema/running-job-executions.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics/index.d.ts +3 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +4 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/metrics/instance.d.ts +34 -0
- package/dist/metrics/instance.d.ts.map +1 -0
- package/dist/metrics/instance.js +60 -0
- package/dist/metrics/instance.js.map +1 -0
- package/dist/metrics/service.d.ts +2 -0
- package/dist/metrics/service.d.ts.map +1 -0
- package/dist/metrics/service.js +21 -0
- package/dist/metrics/service.js.map +1 -0
- package/dist/presentation/auth/index.d.ts +3 -0
- package/dist/presentation/auth/index.d.ts.map +1 -0
- package/dist/presentation/auth/index.js +4 -0
- package/dist/presentation/auth/index.js.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts +3 -0
- package/dist/presentation/auth/provisioner-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/provisioner-token-auth.js +81 -0
- package/dist/presentation/auth/provisioner-token-auth.js.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts +17 -0
- package/dist/presentation/auth/runner-registration-token-auth.d.ts.map +1 -0
- package/dist/presentation/auth/runner-registration-token-auth.js +77 -0
- package/dist/presentation/auth/runner-registration-token-auth.js.map +1 -0
- package/dist/presentation/dto/active-provisioner.d.ts +8 -0
- package/dist/presentation/dto/active-provisioner.d.ts.map +1 -0
- package/dist/presentation/dto/active-provisioner.js +10 -0
- package/dist/presentation/dto/active-provisioner.js.map +1 -0
- package/dist/presentation/dto/index.d.ts +7 -0
- package/dist/presentation/dto/index.d.ts.map +1 -0
- package/dist/presentation/dto/index.js +8 -0
- package/dist/presentation/dto/index.js.map +1 -0
- package/dist/presentation/dto/manual-registration-token.d.ts +12 -0
- package/dist/presentation/dto/manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/dto/manual-registration-token.js +14 -0
- package/dist/presentation/dto/manual-registration-token.js.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts +5 -0
- package/dist/presentation/dto/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/dto/mint-registration-tokens.js +19 -0
- package/dist/presentation/dto/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/dto/poll-demand.d.ts +4 -0
- package/dist/presentation/dto/poll-demand.d.ts.map +1 -0
- package/dist/presentation/dto/poll-demand.js +19 -0
- package/dist/presentation/dto/poll-demand.js.map +1 -0
- package/dist/presentation/dto/provisioned-runners.d.ts +38 -0
- package/dist/presentation/dto/provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/dto/provisioned-runners.js +44 -0
- package/dist/presentation/dto/provisioned-runners.js.map +1 -0
- package/dist/presentation/dto/provisioner-token.d.ts +15 -0
- package/dist/presentation/dto/provisioner-token.d.ts.map +1 -0
- package/dist/presentation/dto/provisioner-token.js +17 -0
- package/dist/presentation/dto/provisioner-token.js.map +1 -0
- package/dist/presentation/index.d.ts +4 -0
- package/dist/presentation/index.d.ts.map +1 -0
- package/dist/presentation/index.js +5 -0
- package/dist/presentation/index.js.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/create-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-manual-registration-token.js +44 -0
- package/dist/presentation/routes/create-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/create-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/create-provisioner-token.js +42 -0
- package/dist/presentation/routes/create-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts +2 -0
- package/dist/presentation/routes/get-provisioner-me.d.ts.map +1 -0
- package/dist/presentation/routes/get-provisioner-me.js +22 -0
- package/dist/presentation/routes/get-provisioner-me.js.map +1 -0
- package/dist/presentation/routes/heartbeat.d.ts +2 -0
- package/dist/presentation/routes/heartbeat.d.ts.map +1 -0
- package/dist/presentation/routes/heartbeat.js +64 -0
- package/dist/presentation/routes/heartbeat.js.map +1 -0
- package/dist/presentation/routes/index.d.ts +4 -0
- package/dist/presentation/routes/index.d.ts.map +1 -0
- package/dist/presentation/routes/index.js +97 -0
- package/dist/presentation/routes/index.js.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts +2 -0
- package/dist/presentation/routes/list-active-provisioners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-provisioners.js +32 -0
- package/dist/presentation/routes/list-active-provisioners.js.map +1 -0
- package/dist/presentation/routes/list-active-runners.d.ts +2 -0
- package/dist/presentation/routes/list-active-runners.d.ts.map +1 -0
- package/dist/presentation/routes/list-active-runners.js +32 -0
- package/dist/presentation/routes/list-active-runners.js.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-manual-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js +32 -0
- package/dist/presentation/routes/list-manual-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts +2 -0
- package/dist/presentation/routes/list-provisioner-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/list-provisioner-tokens.js +32 -0
- package/dist/presentation/routes/list-provisioner-tokens.js.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts +2 -0
- package/dist/presentation/routes/mint-registration-tokens.d.ts.map +1 -0
- package/dist/presentation/routes/mint-registration-tokens.js +74 -0
- package/dist/presentation/routes/mint-registration-tokens.js.map +1 -0
- package/dist/presentation/routes/poll-demand.d.ts +2 -0
- package/dist/presentation/routes/poll-demand.d.ts.map +1 -0
- package/dist/presentation/routes/poll-demand.js +53 -0
- package/dist/presentation/routes/poll-demand.js.map +1 -0
- package/dist/presentation/routes/rate-limit.d.ts +4 -0
- package/dist/presentation/routes/rate-limit.d.ts.map +1 -0
- package/dist/presentation/routes/rate-limit.js +94 -0
- package/dist/presentation/routes/rate-limit.js.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js +27 -0
- package/dist/presentation/routes/reconcile-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/register.d.ts +2 -0
- package/dist/presentation/routes/register.d.ts.map +1 -0
- package/dist/presentation/routes/register.js +63 -0
- package/dist/presentation/routes/register.js.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts +2 -0
- package/dist/presentation/routes/report-provisioned-runners.d.ts.map +1 -0
- package/dist/presentation/routes/report-provisioned-runners.js +37 -0
- package/dist/presentation/routes/report-provisioned-runners.js.map +1 -0
- package/dist/presentation/routes/request-job.d.ts +2 -0
- package/dist/presentation/routes/request-job.d.ts.map +1 -0
- package/dist/presentation/routes/request-job.js +45 -0
- package/dist/presentation/routes/request-job.js.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-manual-registration-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js +42 -0
- package/dist/presentation/routes/revoke-manual-registration-token.js.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts +2 -0
- package/dist/presentation/routes/revoke-provisioner-token.d.ts.map +1 -0
- package/dist/presentation/routes/revoke-provisioner-token.js +44 -0
- package/dist/presentation/routes/revoke-provisioner-token.js.map +1 -0
- package/dist/presentation/routes/workspace-membership.d.ts +6 -0
- package/dist/presentation/routes/workspace-membership.d.ts.map +1 -0
- package/dist/presentation/routes/workspace-membership.js +6 -0
- package/dist/presentation/routes/workspace-membership.js.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts +3 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.d.ts.map +1 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js +14 -0
- package/dist/presentation/subscribers/on-workflows-job-execution-timed-out.js.map +1 -0
- package/dist/temporal/activities/index.d.ts +9 -0
- package/dist/temporal/activities/index.d.ts.map +1 -0
- package/dist/temporal/activities/index.js +12 -0
- package/dist/temporal/activities/index.js.map +1 -0
- package/dist/temporal/activities/maintenance-activities.d.ts +31 -0
- package/dist/temporal/activities/maintenance-activities.d.ts.map +1 -0
- package/dist/temporal/activities/maintenance-activities.js +18 -0
- package/dist/temporal/activities/maintenance-activities.js.map +1 -0
- package/dist/temporal/constants.d.ts +2 -0
- package/dist/temporal/constants.d.ts.map +1 -0
- package/dist/temporal/constants.js +3 -0
- package/dist/temporal/constants.js.map +1 -0
- package/dist/temporal/workflows/index.d.ts +2 -0
- package/dist/temporal/workflows/index.d.ts.map +1 -0
- package/dist/temporal/workflows/index.js +3 -0
- package/dist/temporal/workflows/index.js.map +1 -0
- package/dist/temporal/workflows/stuck-job-detector.d.ts +2 -0
- package/dist/temporal/workflows/stuck-job-detector.d.ts.map +1 -0
- package/dist/temporal/workflows/stuck-job-detector.js +61 -0
- package/dist/temporal/workflows/stuck-job-detector.js.map +1 -0
- package/dist/tsconfig.test.tsbuildinfo +1 -0
- package/drizzle/0000_initial.sql +185 -0
- package/drizzle/meta/0000_snapshot.json +1582 -0
- package/drizzle/meta/_journal.json +13 -0
- package/drizzle.config.ts +7 -0
- package/package.json +82 -0
- package/src/config.test.ts +374 -0
- package/src/config.ts +330 -0
- package/src/core/demand.test.ts +301 -0
- package/src/core/demand.ts +239 -0
- package/src/core/entities/ephemeral-registration-token.ts +13 -0
- package/src/core/entities/manual-registration-token.ts +11 -0
- package/src/core/entities/provisioned-runner.ts +30 -0
- package/src/core/entities/provisioner-token.ts +16 -0
- package/src/core/entities/reservation.ts +9 -0
- package/src/core/entities/runner-session.ts +18 -0
- package/src/core/ephemeral-registration-tokens.test.ts +108 -0
- package/src/core/ephemeral-registration-tokens.ts +112 -0
- package/src/core/errors.ts +128 -0
- package/src/core/index.ts +56 -0
- package/src/core/job-executions.ts +47 -0
- package/src/core/maintenance-policy.ts +1 -0
- package/src/core/maintenance.test.ts +251 -0
- package/src/core/maintenance.ts +74 -0
- package/src/core/manual-registration-tokens.test.ts +44 -0
- package/src/core/manual-registration-tokens.ts +51 -0
- package/src/core/provisioned-runners.test.ts +101 -0
- package/src/core/provisioned-runners.ts +301 -0
- package/src/core/provisioner-tokens.test.ts +61 -0
- package/src/core/provisioner-tokens.ts +61 -0
- package/src/core/rate-limit.test.ts +158 -0
- package/src/core/rate-limit.ts +121 -0
- package/src/core/runner-sessions.test.ts +209 -0
- package/src/core/runner-sessions.ts +66 -0
- package/src/core/runner-tool-capabilities.test.ts +141 -0
- package/src/core/runner-tool-capabilities.ts +75 -0
- package/src/db/db.ts +38 -0
- package/src/db/ephemeral-registration-tokens.test.ts +332 -0
- package/src/db/ephemeral-registration-tokens.ts +348 -0
- package/src/db/index.ts +90 -0
- package/src/db/job-executions.test.ts +1500 -0
- package/src/db/job-executions.ts +647 -0
- package/src/db/manual-registration-tokens.test.ts +99 -0
- package/src/db/manual-registration-tokens.ts +87 -0
- package/src/db/provisioned-runners.test.ts +1812 -0
- package/src/db/provisioned-runners.ts +886 -0
- package/src/db/provisioner-tokens.test.ts +133 -0
- package/src/db/provisioner-tokens.ts +142 -0
- package/src/db/rate-limits.test.ts +74 -0
- package/src/db/rate-limits.ts +69 -0
- package/src/db/reservations.test.ts +399 -0
- package/src/db/reservations.ts +296 -0
- package/src/db/runner-sessions.test.ts +153 -0
- package/src/db/runner-sessions.ts +97 -0
- package/src/db/schema/common.ts +3 -0
- package/src/db/schema/ephemeral-registration-tokens.ts +58 -0
- package/src/db/schema/manual-registration-tokens.ts +40 -0
- package/src/db/schema/outbox.ts +4 -0
- package/src/db/schema/pending-job-executions.ts +25 -0
- package/src/db/schema/provisioned-runners.ts +89 -0
- package/src/db/schema/provisioner-tokens.ts +50 -0
- package/src/db/schema/rate-limits.ts +27 -0
- package/src/db/schema/reservations.ts +38 -0
- package/src/db/schema/runner-sessions.ts +77 -0
- package/src/db/schema/running-job-executions.ts +50 -0
- package/src/index.ts +63 -0
- package/src/metrics/index.ts +13 -0
- package/src/metrics/instance.ts +115 -0
- package/src/metrics/service.ts +22 -0
- package/src/presentation/auth/index.ts +6 -0
- package/src/presentation/auth/provisioner-token-auth.ts +76 -0
- package/src/presentation/auth/runner-registration-token-auth.ts +105 -0
- package/src/presentation/dto/active-provisioner.ts +15 -0
- package/src/presentation/dto/index.ts +13 -0
- package/src/presentation/dto/manual-registration-token.ts +23 -0
- package/src/presentation/dto/mint-registration-tokens.ts +35 -0
- package/src/presentation/dto/poll-demand.ts +20 -0
- package/src/presentation/dto/provisioned-runners.ts +88 -0
- package/src/presentation/dto/provisioner-token.ts +29 -0
- package/src/presentation/index.ts +6 -0
- package/src/presentation/routes/create-manual-registration-token.ts +43 -0
- package/src/presentation/routes/create-provisioner-token.ts +41 -0
- package/src/presentation/routes/get-provisioner-me.ts +22 -0
- package/src/presentation/routes/heartbeat.test.ts +325 -0
- package/src/presentation/routes/heartbeat.ts +80 -0
- package/src/presentation/routes/index.ts +86 -0
- package/src/presentation/routes/list-active-provisioners.ts +25 -0
- package/src/presentation/routes/list-active-runners.test.ts +366 -0
- package/src/presentation/routes/list-active-runners.ts +25 -0
- package/src/presentation/routes/list-manual-registration-tokens.ts +25 -0
- package/src/presentation/routes/list-provisioner-tokens.ts +25 -0
- package/src/presentation/routes/manual-registration-tokens.test.ts +213 -0
- package/src/presentation/routes/mint-registration-tokens.test.ts +453 -0
- package/src/presentation/routes/mint-registration-tokens.ts +82 -0
- package/src/presentation/routes/poll-demand-release.test.ts +80 -0
- package/src/presentation/routes/poll-demand.test.ts +323 -0
- package/src/presentation/routes/poll-demand.ts +56 -0
- package/src/presentation/routes/provisioner-me.test.ts +172 -0
- package/src/presentation/routes/provisioner-tokens.test.ts +219 -0
- package/src/presentation/routes/rate-limit.ts +115 -0
- package/src/presentation/routes/reconcile-provisioned-runners.test.ts +380 -0
- package/src/presentation/routes/reconcile-provisioned-runners.ts +30 -0
- package/src/presentation/routes/register.test.ts +453 -0
- package/src/presentation/routes/register.ts +75 -0
- package/src/presentation/routes/report-provisioned-runners.test.ts +249 -0
- package/src/presentation/routes/report-provisioned-runners.ts +40 -0
- package/src/presentation/routes/request-job.test.ts +222 -0
- package/src/presentation/routes/request-job.ts +47 -0
- package/src/presentation/routes/revoke-manual-registration-token.ts +35 -0
- package/src/presentation/routes/revoke-provisioner-token.ts +37 -0
- package/src/presentation/routes/workspace-membership.ts +9 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.test.ts +147 -0
- package/src/presentation/subscribers/on-workflows-job-execution-timed-out.ts +17 -0
- package/src/temporal/activities/index.ts +17 -0
- package/src/temporal/activities/maintenance-activities.test.ts +104 -0
- package/src/temporal/activities/maintenance-activities.ts +41 -0
- package/src/temporal/constants.ts +1 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/stuck-job-detector.test.ts +93 -0
- package/src/temporal/workflows/stuck-job-detector.ts +67 -0
- package/test/env.ts +11 -0
- package/test/factories/ephemeral-registration-token.ts +41 -0
- package/test/factories/manual-registration-token.ts +37 -0
- package/test/factories/pending-job.ts +44 -0
- package/test/factories/provisioned-runner.ts +78 -0
- package/test/factories/provisioner-token.ts +41 -0
- package/test/factories/reservation.ts +33 -0
- package/test/factories/runner-session.ts +32 -0
- package/test/globalSetup.ts +23 -0
- package/test/index.ts +16 -0
- package/test/setup.ts +17 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.test.json +8 -0
- package/vitest.config.ts +14 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import {and, eq, inArray} from 'drizzle-orm';
|
|
2
|
+
import {db} from '#db/db.js';
|
|
3
|
+
import {deleteExpiredRunnerSessions} from '#db/runner-sessions.js';
|
|
4
|
+
import {runnerSessions} from '#db/schema/runner-sessions.js';
|
|
5
|
+
import {runningJobExecutions} from '#db/schema/running-job-executions.js';
|
|
6
|
+
|
|
7
|
+
describe('deleteExpiredRunnerSessions', () => {
|
|
8
|
+
let workspaceId: string;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
workspaceId = crypto.randomUUID();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('deletes manual sessions older than the manual retention window', async () => {
|
|
15
|
+
const expired = await insertRunnerSession({kind: 'manual', createdDaysAgo: 31});
|
|
16
|
+
const active = await insertRunnerSession({kind: 'manual', createdDaysAgo: 29});
|
|
17
|
+
|
|
18
|
+
const deleted = await deleteExpiredRunnerSessions({
|
|
19
|
+
manualRetentionDays: 30,
|
|
20
|
+
ephemeralRetentionDays: 7,
|
|
21
|
+
limit: 100,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const remaining = await listRunnerSessionIds([expired, active]);
|
|
25
|
+
expect(deleted).toBeGreaterThanOrEqual(1);
|
|
26
|
+
expect(remaining).toEqual([active]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('deletes ephemeral sessions older than the ephemeral retention window', async () => {
|
|
30
|
+
const expired = await insertRunnerSession({kind: 'ephemeral', createdDaysAgo: 8});
|
|
31
|
+
const active = await insertRunnerSession({kind: 'ephemeral', createdDaysAgo: 6});
|
|
32
|
+
|
|
33
|
+
const deleted = await deleteExpiredRunnerSessions({
|
|
34
|
+
manualRetentionDays: 30,
|
|
35
|
+
ephemeralRetentionDays: 7,
|
|
36
|
+
limit: 100,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const remaining = await listRunnerSessionIds([expired, active]);
|
|
40
|
+
expect(deleted).toBeGreaterThanOrEqual(1);
|
|
41
|
+
expect(remaining).toEqual([active]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('applies the retention window for each registration token kind independently', async () => {
|
|
45
|
+
const manualExpired = await insertRunnerSession({kind: 'manual', createdDaysAgo: 31});
|
|
46
|
+
const manualActive = await insertRunnerSession({kind: 'manual', createdDaysAgo: 8});
|
|
47
|
+
const ephemeralExpired = await insertRunnerSession({kind: 'ephemeral', createdDaysAgo: 8});
|
|
48
|
+
const ephemeralActive = await insertRunnerSession({kind: 'ephemeral', createdDaysAgo: 6});
|
|
49
|
+
|
|
50
|
+
await deleteExpiredRunnerSessions({
|
|
51
|
+
manualRetentionDays: 30,
|
|
52
|
+
ephemeralRetentionDays: 7,
|
|
53
|
+
limit: 100,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const remaining = await listRunnerSessionIds([
|
|
57
|
+
manualExpired,
|
|
58
|
+
manualActive,
|
|
59
|
+
ephemeralExpired,
|
|
60
|
+
ephemeralActive,
|
|
61
|
+
]);
|
|
62
|
+
expect(remaining).toEqual([manualActive, ephemeralActive]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('keeps expired sessions referenced by running jobs', async () => {
|
|
66
|
+
const expired = await insertRunnerSession({kind: 'manual', createdDaysAgo: 31});
|
|
67
|
+
await insertRunningJob(expired);
|
|
68
|
+
|
|
69
|
+
const deleted = await deleteExpiredRunnerSessions({
|
|
70
|
+
manualRetentionDays: 30,
|
|
71
|
+
ephemeralRetentionDays: 7,
|
|
72
|
+
limit: 100,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const remaining = await listRunnerSessionIds([expired]);
|
|
76
|
+
expect(deleted).toBe(0);
|
|
77
|
+
expect(remaining).toEqual([expired]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('honors the deletion limit', async () => {
|
|
81
|
+
const first = await insertRunnerSession({kind: 'manual', createdDaysAgo: 3652});
|
|
82
|
+
const second = await insertRunnerSession({kind: 'manual', createdDaysAgo: 3651});
|
|
83
|
+
const third = await insertRunnerSession({kind: 'manual', createdDaysAgo: 3650});
|
|
84
|
+
|
|
85
|
+
const deleted = await deleteExpiredRunnerSessions({
|
|
86
|
+
manualRetentionDays: 30,
|
|
87
|
+
ephemeralRetentionDays: 7,
|
|
88
|
+
limit: 2,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const remaining = await listRunnerSessionIds([first, second, third]);
|
|
92
|
+
expect(deleted).toBe(2);
|
|
93
|
+
expect(remaining).toHaveLength(1);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
async function insertRunnerSession(params: {
|
|
97
|
+
kind: 'manual' | 'ephemeral';
|
|
98
|
+
createdDaysAgo: number;
|
|
99
|
+
}): Promise<string> {
|
|
100
|
+
const id = crypto.randomUUID();
|
|
101
|
+
const registrationTokenId = crypto.randomUUID();
|
|
102
|
+
const createdAt = new Date(Date.now() - params.createdDaysAgo * 24 * 60 * 60 * 1000);
|
|
103
|
+
const provisionerId = params.kind === 'ephemeral' ? crypto.randomUUID() : null;
|
|
104
|
+
const provisionedRunnerId =
|
|
105
|
+
params.kind === 'ephemeral' ? `provisioned-${crypto.randomUUID()}` : null;
|
|
106
|
+
|
|
107
|
+
await db()
|
|
108
|
+
.insert(runnerSessions)
|
|
109
|
+
.values({
|
|
110
|
+
id,
|
|
111
|
+
workspaceId,
|
|
112
|
+
scope: 'workspace',
|
|
113
|
+
registrationTokenId,
|
|
114
|
+
registrationTokenKind: params.kind,
|
|
115
|
+
provisionerId,
|
|
116
|
+
provisionedRunnerId,
|
|
117
|
+
labels: ['linux'],
|
|
118
|
+
maxClaims: params.kind === 'ephemeral' ? 1 : null,
|
|
119
|
+
claimsUsed: 0,
|
|
120
|
+
createdAt,
|
|
121
|
+
updatedAt: createdAt,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
return id;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function insertRunningJob(runnerSessionId: string): Promise<void> {
|
|
128
|
+
await db()
|
|
129
|
+
.insert(runningJobExecutions)
|
|
130
|
+
.values({
|
|
131
|
+
workspaceId,
|
|
132
|
+
workflowRunId: crypto.randomUUID(),
|
|
133
|
+
workflowRunAttemptId: crypto.randomUUID(),
|
|
134
|
+
jobId: crypto.randomUUID(),
|
|
135
|
+
jobExecutionId: crypto.randomUUID(),
|
|
136
|
+
projectId: crypto.randomUUID(),
|
|
137
|
+
runnerSessionId,
|
|
138
|
+
requiredLabels: ['linux'],
|
|
139
|
+
runnerLabels: ['linux'],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function listRunnerSessionIds(ids: string[]): Promise<string[]> {
|
|
144
|
+
if (ids.length === 0) return [];
|
|
145
|
+
|
|
146
|
+
const rows = await db()
|
|
147
|
+
.select({id: runnerSessions.id})
|
|
148
|
+
.from(runnerSessions)
|
|
149
|
+
.where(and(eq(runnerSessions.workspaceId, workspaceId), inArray(runnerSessions.id, ids)));
|
|
150
|
+
|
|
151
|
+
return ids.filter((id) => rows.some((row) => row.id === id));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {and, asc, eq, inArray, lt, notExists, or, sql} from 'drizzle-orm';
|
|
3
|
+
import type {RunnerSession} from '#core/entities/runner-session.js';
|
|
4
|
+
import {db} from './db.js';
|
|
5
|
+
import {runnerSessions, toRunnerSession} from './schema/runner-sessions.js';
|
|
6
|
+
import {runningJobExecutions} from './schema/running-job-executions.js';
|
|
7
|
+
|
|
8
|
+
export interface CreateRunnerSessionParams {
|
|
9
|
+
workspaceId: string;
|
|
10
|
+
scope: 'workspace';
|
|
11
|
+
registrationTokenId: string;
|
|
12
|
+
labels: string[];
|
|
13
|
+
toolCapabilities?: RunnerToolCapabilitiesDto | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export async function createRunnerSession(
|
|
17
|
+
params: CreateRunnerSessionParams,
|
|
18
|
+
): Promise<RunnerSession> {
|
|
19
|
+
const rows = await db()
|
|
20
|
+
.insert(runnerSessions)
|
|
21
|
+
.values({
|
|
22
|
+
workspaceId: params.workspaceId,
|
|
23
|
+
scope: params.scope,
|
|
24
|
+
registrationTokenId: params.registrationTokenId,
|
|
25
|
+
registrationTokenKind: 'manual',
|
|
26
|
+
labels: params.labels,
|
|
27
|
+
toolCapabilities: params.toolCapabilities ?? null,
|
|
28
|
+
toolCapabilitiesReportedAt: params.toolCapabilities ? sql`now()` : null,
|
|
29
|
+
maxClaims: null,
|
|
30
|
+
claimsUsed: 0,
|
|
31
|
+
})
|
|
32
|
+
.returning();
|
|
33
|
+
|
|
34
|
+
const row = rows[0];
|
|
35
|
+
if (!row) throw new Error('Insert returned no rows');
|
|
36
|
+
return toRunnerSession(row);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function getRunnerSessionById(runnerSessionId: string): Promise<RunnerSession | null> {
|
|
40
|
+
const rows = await db()
|
|
41
|
+
.select()
|
|
42
|
+
.from(runnerSessions)
|
|
43
|
+
.where(eq(runnerSessions.id, runnerSessionId))
|
|
44
|
+
.limit(1);
|
|
45
|
+
|
|
46
|
+
const row = rows[0];
|
|
47
|
+
return row ? toRunnerSession(row) : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DeleteExpiredRunnerSessionsParams {
|
|
51
|
+
manualRetentionDays: number;
|
|
52
|
+
ephemeralRetentionDays: number;
|
|
53
|
+
limit?: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function deleteExpiredRunnerSessions(
|
|
57
|
+
params: DeleteExpiredRunnerSessionsParams,
|
|
58
|
+
): Promise<number> {
|
|
59
|
+
const expiredIds = db()
|
|
60
|
+
.select({id: runnerSessions.id})
|
|
61
|
+
.from(runnerSessions)
|
|
62
|
+
.where(
|
|
63
|
+
and(
|
|
64
|
+
or(
|
|
65
|
+
and(
|
|
66
|
+
eq(runnerSessions.registrationTokenKind, 'manual'),
|
|
67
|
+
lt(
|
|
68
|
+
runnerSessions.createdAt,
|
|
69
|
+
sql`now() - (${params.manualRetentionDays} || ' days')::interval`,
|
|
70
|
+
),
|
|
71
|
+
),
|
|
72
|
+
and(
|
|
73
|
+
eq(runnerSessions.registrationTokenKind, 'ephemeral'),
|
|
74
|
+
lt(
|
|
75
|
+
runnerSessions.createdAt,
|
|
76
|
+
sql`now() - (${params.ephemeralRetentionDays} || ' days')::interval`,
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
notExists(
|
|
81
|
+
db()
|
|
82
|
+
.select({id: runningJobExecutions.id})
|
|
83
|
+
.from(runningJobExecutions)
|
|
84
|
+
.where(eq(runningJobExecutions.runnerSessionId, runnerSessions.id)),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
)
|
|
88
|
+
.orderBy(asc(runnerSessions.createdAt), asc(runnerSessions.id))
|
|
89
|
+
.limit(params.limit ?? 1000);
|
|
90
|
+
|
|
91
|
+
const deleted = await db()
|
|
92
|
+
.delete(runnerSessions)
|
|
93
|
+
.where(inArray(runnerSessions.id, expiredIds))
|
|
94
|
+
.returning({id: runnerSessions.id});
|
|
95
|
+
|
|
96
|
+
return deleted.length;
|
|
97
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {sql} from 'drizzle-orm';
|
|
3
|
+
import {index, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
4
|
+
import type {EphemeralRegistrationToken} from '#core/entities/ephemeral-registration-token.js';
|
|
5
|
+
import {pgTable} from './common.js';
|
|
6
|
+
|
|
7
|
+
export const ephemeralRegistrationTokens = pgTable(
|
|
8
|
+
'ephemeral_registration_tokens',
|
|
9
|
+
{
|
|
10
|
+
id: uuidv7PrimaryKey(),
|
|
11
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
12
|
+
provisionerId: uuid('provisioner_id').notNull(),
|
|
13
|
+
reservationId: uuid('reservation_id'),
|
|
14
|
+
provisionedRunnerId: text('provisioned_runner_id').notNull(),
|
|
15
|
+
hashedToken: text('hashed_token').notNull(),
|
|
16
|
+
prefix: text('prefix').notNull(),
|
|
17
|
+
expiresAt: timestamp('expires_at', {withTimezone: true}).notNull(),
|
|
18
|
+
consumedAt: timestamp('consumed_at', {withTimezone: true}),
|
|
19
|
+
consumedSessionId: uuid('consumed_session_id'),
|
|
20
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
21
|
+
},
|
|
22
|
+
(table) => [
|
|
23
|
+
uniqueIndex('runners_ephemeral_registration_tokens_hashed_token_unique').on(table.hashedToken),
|
|
24
|
+
index('runners_ephemeral_registration_tokens_reservation_id_idx').on(table.reservationId),
|
|
25
|
+
index('runners_ephemeral_registration_tokens_active_provisioned_runner_idx').on(
|
|
26
|
+
table.workspaceId,
|
|
27
|
+
table.provisionerId,
|
|
28
|
+
table.provisionedRunnerId,
|
|
29
|
+
table.consumedAt,
|
|
30
|
+
table.expiresAt,
|
|
31
|
+
),
|
|
32
|
+
index('runners_ephemeral_registration_tokens_terminal_idx').on(
|
|
33
|
+
sql`coalesce(${table.consumedAt}, ${table.expiresAt})`,
|
|
34
|
+
table.id,
|
|
35
|
+
),
|
|
36
|
+
],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export type EphemeralRegistrationTokenDb = typeof ephemeralRegistrationTokens.$inferSelect;
|
|
40
|
+
export type EphemeralRegistrationTokenInsertDb = typeof ephemeralRegistrationTokens.$inferInsert;
|
|
41
|
+
|
|
42
|
+
export function toEphemeralRegistrationToken(
|
|
43
|
+
row: EphemeralRegistrationTokenDb,
|
|
44
|
+
): EphemeralRegistrationToken {
|
|
45
|
+
return {
|
|
46
|
+
id: row.id,
|
|
47
|
+
workspaceId: row.workspaceId,
|
|
48
|
+
provisionerId: row.provisionerId,
|
|
49
|
+
reservationId: row.reservationId,
|
|
50
|
+
provisionedRunnerId: row.provisionedRunnerId,
|
|
51
|
+
hashedToken: row.hashedToken,
|
|
52
|
+
prefix: row.prefix,
|
|
53
|
+
expiresAt: row.expiresAt,
|
|
54
|
+
consumedAt: row.consumedAt,
|
|
55
|
+
consumedSessionId: row.consumedSessionId,
|
|
56
|
+
createdAt: row.createdAt,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {index, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
3
|
+
import type {ManualRegistrationToken} from '#core/entities/manual-registration-token.js';
|
|
4
|
+
import {pgTable} from './common.js';
|
|
5
|
+
|
|
6
|
+
export const manualRegistrationTokens = pgTable(
|
|
7
|
+
'manual_registration_tokens',
|
|
8
|
+
{
|
|
9
|
+
id: uuidv7PrimaryKey(),
|
|
10
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
11
|
+
hashedToken: text('hashed_token').notNull(),
|
|
12
|
+
prefix: text('prefix').notNull(),
|
|
13
|
+
name: text('name'),
|
|
14
|
+
expiresAt: timestamp('expires_at', {withTimezone: true}),
|
|
15
|
+
revokedAt: timestamp('revoked_at', {withTimezone: true}),
|
|
16
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
17
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
18
|
+
},
|
|
19
|
+
(table) => [
|
|
20
|
+
uniqueIndex('runners_manual_registration_tokens_hashed_token_unique').on(table.hashedToken),
|
|
21
|
+
index('runners_manual_registration_tokens_workspace_id_idx').on(table.workspaceId),
|
|
22
|
+
],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type ManualRegistrationTokenDb = typeof manualRegistrationTokens.$inferSelect;
|
|
26
|
+
export type ManualRegistrationTokenInsertDb = typeof manualRegistrationTokens.$inferInsert;
|
|
27
|
+
|
|
28
|
+
export function toManualRegistrationToken(row: ManualRegistrationTokenDb): ManualRegistrationToken {
|
|
29
|
+
return {
|
|
30
|
+
id: row.id,
|
|
31
|
+
workspaceId: row.workspaceId,
|
|
32
|
+
hashedToken: row.hashedToken,
|
|
33
|
+
prefix: row.prefix,
|
|
34
|
+
name: row.name,
|
|
35
|
+
expiresAt: row.expiresAt,
|
|
36
|
+
revokedAt: row.revokedAt,
|
|
37
|
+
createdAt: row.createdAt,
|
|
38
|
+
updatedAt: row.updatedAt,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {index, text, timestamp, uuid} from 'drizzle-orm/pg-core';
|
|
3
|
+
import {pgTable} from './common.js';
|
|
4
|
+
|
|
5
|
+
export const pendingJobExecutions = pgTable(
|
|
6
|
+
'pending_jobs',
|
|
7
|
+
{
|
|
8
|
+
id: uuidv7PrimaryKey(),
|
|
9
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
10
|
+
workflowRunId: uuid('workflow_run_id').notNull(),
|
|
11
|
+
workflowRunAttemptId: uuid('workflow_run_attempt_id').notNull(),
|
|
12
|
+
jobId: uuid('job_id').notNull(),
|
|
13
|
+
jobExecutionId: uuid('job_execution_id').notNull().unique(),
|
|
14
|
+
projectId: uuid('project_id').notNull(),
|
|
15
|
+
requiredLabels: text('required_labels').array().notNull(),
|
|
16
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
17
|
+
},
|
|
18
|
+
(table) => [
|
|
19
|
+
index('runners_pending_jobs_workspace_created_idx').on(table.workspaceId, table.createdAt),
|
|
20
|
+
index('runners_pending_jobs_job_id_idx').on(table.jobId),
|
|
21
|
+
],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export type PendingJobExecutionDb = typeof pendingJobExecutions.$inferSelect;
|
|
25
|
+
export type PendingJobExecutionInsertDb = typeof pendingJobExecutions.$inferInsert;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {sql} from 'drizzle-orm';
|
|
3
|
+
import {index, pgEnum, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
4
|
+
import type {ProvisionedRunner} from '#core/entities/provisioned-runner.js';
|
|
5
|
+
import {pgTable} from './common.js';
|
|
6
|
+
|
|
7
|
+
export const provisionedRunnerStateEnum = pgEnum('runners_provisioned_runner_state', [
|
|
8
|
+
'starting',
|
|
9
|
+
'running',
|
|
10
|
+
'stopping',
|
|
11
|
+
'stopped',
|
|
12
|
+
'failed',
|
|
13
|
+
'terminated',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export const provisionedRunners = pgTable(
|
|
17
|
+
'provisioned_runners',
|
|
18
|
+
{
|
|
19
|
+
id: uuidv7PrimaryKey(),
|
|
20
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
21
|
+
provisionerId: uuid('provisioner_id').notNull(),
|
|
22
|
+
provisionedRunnerId: text('provisioned_runner_id').notNull(),
|
|
23
|
+
reservationId: uuid('reservation_id'),
|
|
24
|
+
templateKey: text('template_key'),
|
|
25
|
+
labels: text('labels').array().notNull(),
|
|
26
|
+
state: provisionedRunnerStateEnum('state').notNull(),
|
|
27
|
+
reason: text('reason'),
|
|
28
|
+
runnerSessionId: uuid('runner_session_id'),
|
|
29
|
+
providerKind: text('provider_kind'),
|
|
30
|
+
reportedAt: timestamp('reported_at', {withTimezone: true}).notNull(),
|
|
31
|
+
startedAt: timestamp('started_at', {withTimezone: true}),
|
|
32
|
+
stoppingAt: timestamp('stopping_at', {withTimezone: true}),
|
|
33
|
+
stoppedAt: timestamp('stopped_at', {withTimezone: true}),
|
|
34
|
+
failedAt: timestamp('failed_at', {withTimezone: true}),
|
|
35
|
+
terminatedAt: timestamp('terminated_at', {withTimezone: true}),
|
|
36
|
+
reservationReleasedAt: timestamp('reservation_released_at', {withTimezone: true}),
|
|
37
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
38
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
39
|
+
},
|
|
40
|
+
(table) => [
|
|
41
|
+
uniqueIndex('runners_provisioned_runners_workspace_provisioner_runner_unique').on(
|
|
42
|
+
table.workspaceId,
|
|
43
|
+
table.provisionerId,
|
|
44
|
+
table.provisionedRunnerId,
|
|
45
|
+
),
|
|
46
|
+
index('runners_provisioned_runners_workspace_state_updated_idx').on(
|
|
47
|
+
table.workspaceId,
|
|
48
|
+
table.state,
|
|
49
|
+
table.updatedAt,
|
|
50
|
+
),
|
|
51
|
+
index('runners_provisioned_runners_stale_reaper_idx').on(
|
|
52
|
+
table.state,
|
|
53
|
+
table.updatedAt,
|
|
54
|
+
table.reportedAt,
|
|
55
|
+
table.workspaceId,
|
|
56
|
+
),
|
|
57
|
+
index('runners_provisioned_runners_active_template_counts_idx')
|
|
58
|
+
.on(table.workspaceId, table.provisionerId, table.state, table.templateKey)
|
|
59
|
+
.where(sql`"state" in ('starting', 'running') and "template_key" is not null`),
|
|
60
|
+
],
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export type ProvisionedRunnerDb = typeof provisionedRunners.$inferSelect;
|
|
64
|
+
export type ProvisionedRunnerInsertDb = typeof provisionedRunners.$inferInsert;
|
|
65
|
+
|
|
66
|
+
export function toProvisionedRunner(row: ProvisionedRunnerDb): ProvisionedRunner {
|
|
67
|
+
return {
|
|
68
|
+
id: row.id,
|
|
69
|
+
workspaceId: row.workspaceId,
|
|
70
|
+
provisionerId: row.provisionerId,
|
|
71
|
+
provisionedRunnerId: row.provisionedRunnerId,
|
|
72
|
+
reservationId: row.reservationId,
|
|
73
|
+
templateKey: row.templateKey,
|
|
74
|
+
labels: row.labels,
|
|
75
|
+
state: row.state,
|
|
76
|
+
reason: row.reason,
|
|
77
|
+
runnerSessionId: row.runnerSessionId,
|
|
78
|
+
providerKind: row.providerKind,
|
|
79
|
+
reportedAt: row.reportedAt,
|
|
80
|
+
startedAt: row.startedAt,
|
|
81
|
+
stoppingAt: row.stoppingAt,
|
|
82
|
+
stoppedAt: row.stoppedAt,
|
|
83
|
+
failedAt: row.failedAt,
|
|
84
|
+
terminatedAt: row.terminatedAt,
|
|
85
|
+
reservationReleasedAt: row.reservationReleasedAt,
|
|
86
|
+
createdAt: row.createdAt,
|
|
87
|
+
updatedAt: row.updatedAt,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {index, text, timestamp, uniqueIndex, uuid} from 'drizzle-orm/pg-core';
|
|
3
|
+
import type {ProvisionerToken} from '#core/entities/provisioner-token.js';
|
|
4
|
+
import {pgTable} from './common.js';
|
|
5
|
+
|
|
6
|
+
export const provisionerTokens = pgTable(
|
|
7
|
+
'provisioner_tokens',
|
|
8
|
+
{
|
|
9
|
+
id: uuidv7PrimaryKey(),
|
|
10
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
11
|
+
hashedToken: text('hashed_token').notNull(),
|
|
12
|
+
prefix: text('prefix').notNull(),
|
|
13
|
+
name: text('name'),
|
|
14
|
+
createdByUserId: uuid('created_by_user_id').notNull(),
|
|
15
|
+
revokedByUserId: uuid('revoked_by_user_id'),
|
|
16
|
+
expiresAt: timestamp('expires_at', {withTimezone: true}),
|
|
17
|
+
revokedAt: timestamp('revoked_at', {withTimezone: true}),
|
|
18
|
+
lastSeenAt: timestamp('last_seen_at', {withTimezone: true}),
|
|
19
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
20
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
21
|
+
},
|
|
22
|
+
(table) => [
|
|
23
|
+
uniqueIndex('runners_provisioner_tokens_hashed_token_unique').on(table.hashedToken),
|
|
24
|
+
index('runners_provisioner_tokens_workspace_last_seen_idx').on(
|
|
25
|
+
table.workspaceId,
|
|
26
|
+
table.lastSeenAt.desc(),
|
|
27
|
+
table.id.desc(),
|
|
28
|
+
),
|
|
29
|
+
],
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export type ProvisionerTokenDb = typeof provisionerTokens.$inferSelect;
|
|
33
|
+
export type ProvisionerTokenInsertDb = typeof provisionerTokens.$inferInsert;
|
|
34
|
+
|
|
35
|
+
export function toProvisionerToken(row: ProvisionerTokenDb): ProvisionerToken {
|
|
36
|
+
return {
|
|
37
|
+
id: row.id,
|
|
38
|
+
workspaceId: row.workspaceId,
|
|
39
|
+
hashedToken: row.hashedToken,
|
|
40
|
+
prefix: row.prefix,
|
|
41
|
+
name: row.name,
|
|
42
|
+
createdByUserId: row.createdByUserId,
|
|
43
|
+
revokedByUserId: row.revokedByUserId,
|
|
44
|
+
expiresAt: row.expiresAt,
|
|
45
|
+
revokedAt: row.revokedAt,
|
|
46
|
+
lastSeenAt: row.lastSeenAt,
|
|
47
|
+
createdAt: row.createdAt,
|
|
48
|
+
updatedAt: row.updatedAt,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {index, integer, text, timestamp, uniqueIndex} from 'drizzle-orm/pg-core';
|
|
2
|
+
import {pgTable} from './common.js';
|
|
3
|
+
|
|
4
|
+
export const runnersRateLimits = pgTable(
|
|
5
|
+
'rate_limits',
|
|
6
|
+
{
|
|
7
|
+
action: text('action').notNull(),
|
|
8
|
+
scope: text('scope').notNull(),
|
|
9
|
+
identifierHmac: text('identifier_hmac').notNull(),
|
|
10
|
+
windowStart: timestamp('window_start', {withTimezone: true}).notNull(),
|
|
11
|
+
count: integer('count').notNull().default(1),
|
|
12
|
+
expiresAt: timestamp('expires_at', {withTimezone: true}).notNull(),
|
|
13
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
14
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
15
|
+
},
|
|
16
|
+
(table) => [
|
|
17
|
+
uniqueIndex('runners_rate_limits_window_unique').on(
|
|
18
|
+
table.action,
|
|
19
|
+
table.scope,
|
|
20
|
+
table.identifierHmac,
|
|
21
|
+
table.windowStart,
|
|
22
|
+
),
|
|
23
|
+
index('runners_rate_limits_expires_at_idx').on(table.expiresAt),
|
|
24
|
+
],
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export type RunnersRateLimitDb = typeof runnersRateLimits.$inferSelect;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
2
|
+
import {sql} from 'drizzle-orm';
|
|
3
|
+
import {check, index, integer, text, timestamp, uuid} from 'drizzle-orm/pg-core';
|
|
4
|
+
import type {Reservation} from '#core/entities/reservation.js';
|
|
5
|
+
import {pgTable} from './common.js';
|
|
6
|
+
|
|
7
|
+
export const reservations = pgTable(
|
|
8
|
+
'reservations',
|
|
9
|
+
{
|
|
10
|
+
id: uuidv7PrimaryKey(),
|
|
11
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
12
|
+
provisionerId: uuid('provisioner_id').notNull(),
|
|
13
|
+
requiredLabels: text('required_labels').array().notNull(),
|
|
14
|
+
count: integer('count').notNull(),
|
|
15
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
16
|
+
expiresAt: timestamp('expires_at', {withTimezone: true}).notNull(),
|
|
17
|
+
},
|
|
18
|
+
(table) => [
|
|
19
|
+
index('runners_reservations_workspace_expires_idx').on(table.workspaceId, table.expiresAt),
|
|
20
|
+
index('runners_reservations_expires_idx').on(table.expiresAt),
|
|
21
|
+
check('runners_reservations_count_positive_ck', sql`${table.count} > 0`),
|
|
22
|
+
],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export type ReservationDb = typeof reservations.$inferSelect;
|
|
26
|
+
export type ReservationInsertDb = typeof reservations.$inferInsert;
|
|
27
|
+
|
|
28
|
+
export function toReservation(row: ReservationDb): Reservation {
|
|
29
|
+
return {
|
|
30
|
+
id: row.id,
|
|
31
|
+
workspaceId: row.workspaceId,
|
|
32
|
+
provisionerId: row.provisionerId,
|
|
33
|
+
requiredLabels: row.requiredLabels,
|
|
34
|
+
count: row.count,
|
|
35
|
+
createdAt: row.createdAt,
|
|
36
|
+
expiresAt: row.expiresAt,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type {RunnerToolCapabilitiesDto} from '@shipfox/api-runners-dto';
|
|
2
|
+
import {uuidv7PrimaryKey} from '@shipfox/node-drizzle';
|
|
3
|
+
import {sql} from 'drizzle-orm';
|
|
4
|
+
import {check, index, integer, jsonb, pgEnum, text, timestamp, uuid} from 'drizzle-orm/pg-core';
|
|
5
|
+
import type {RunnerSession} from '#core/entities/runner-session.js';
|
|
6
|
+
import {pgTable} from './common.js';
|
|
7
|
+
|
|
8
|
+
export const runnerSessionScopeEnum = pgEnum('runners_runner_session_scope', ['workspace']);
|
|
9
|
+
export const runnerSessionRegistrationTokenKindEnum = pgEnum(
|
|
10
|
+
'runners_runner_session_registration_token_kind',
|
|
11
|
+
['manual', 'ephemeral'],
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const runnerSessions = pgTable(
|
|
15
|
+
'runner_sessions',
|
|
16
|
+
{
|
|
17
|
+
id: uuidv7PrimaryKey(),
|
|
18
|
+
workspaceId: uuid('workspace_id').notNull(),
|
|
19
|
+
scope: runnerSessionScopeEnum('scope').notNull().default('workspace'),
|
|
20
|
+
registrationTokenId: uuid('registration_token_id').notNull(),
|
|
21
|
+
registrationTokenKind:
|
|
22
|
+
runnerSessionRegistrationTokenKindEnum('registration_token_kind').notNull(),
|
|
23
|
+
provisionerId: uuid('provisioner_id'),
|
|
24
|
+
provisionedRunnerId: text('provisioned_runner_id'),
|
|
25
|
+
labels: text('labels').array().notNull(),
|
|
26
|
+
toolCapabilities: jsonb('tool_capabilities').$type<RunnerToolCapabilitiesDto | null>(),
|
|
27
|
+
toolCapabilitiesReportedAt: timestamp('tool_capabilities_reported_at', {withTimezone: true}),
|
|
28
|
+
maxClaims: integer('max_claims'),
|
|
29
|
+
claimsUsed: integer('claims_used').notNull().default(0),
|
|
30
|
+
createdAt: timestamp('created_at', {withTimezone: true}).notNull().defaultNow(),
|
|
31
|
+
updatedAt: timestamp('updated_at', {withTimezone: true}).notNull().defaultNow(),
|
|
32
|
+
},
|
|
33
|
+
(table) => [
|
|
34
|
+
index('runners_runner_sessions_kind_created_id_idx').on(
|
|
35
|
+
table.registrationTokenKind,
|
|
36
|
+
table.createdAt,
|
|
37
|
+
table.id,
|
|
38
|
+
),
|
|
39
|
+
check(
|
|
40
|
+
'runners_runner_sessions_claims_ck',
|
|
41
|
+
sql`${table.claimsUsed} >= 0 AND ((${table.registrationTokenKind} = 'manual' AND ${table.maxClaims} IS NULL) OR (${table.registrationTokenKind} = 'ephemeral' AND ${table.maxClaims} IS NOT NULL AND ${table.maxClaims} > 0 AND ${table.claimsUsed} <= ${table.maxClaims}))`,
|
|
42
|
+
),
|
|
43
|
+
check(
|
|
44
|
+
'runners_runner_sessions_link_ck',
|
|
45
|
+
sql`((${table.registrationTokenKind} = 'manual' AND ${table.provisionerId} IS NULL AND ${table.provisionedRunnerId} IS NULL) OR (${table.registrationTokenKind} = 'ephemeral' AND ${table.provisionerId} IS NOT NULL AND ${table.provisionedRunnerId} IS NOT NULL))`,
|
|
46
|
+
),
|
|
47
|
+
index('runners_runner_sessions_provisioned_runner_updated_idx')
|
|
48
|
+
.on(table.workspaceId, table.provisionerId, table.provisionedRunnerId, table.updatedAt)
|
|
49
|
+
.where(sql`"provisioner_id" IS NOT NULL`),
|
|
50
|
+
],
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export type RunnerSessionDb = typeof runnerSessions.$inferSelect;
|
|
54
|
+
export type RunnerSessionInsertDb = typeof runnerSessions.$inferInsert;
|
|
55
|
+
|
|
56
|
+
export function toRunnerSession(row: RunnerSessionDb): RunnerSession {
|
|
57
|
+
if (row.scope !== 'workspace') {
|
|
58
|
+
throw new Error(`Unexpected runner session scope: ${row.scope}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
id: row.id,
|
|
63
|
+
workspaceId: row.workspaceId,
|
|
64
|
+
scope: row.scope,
|
|
65
|
+
registrationTokenId: row.registrationTokenId,
|
|
66
|
+
registrationTokenKind: row.registrationTokenKind,
|
|
67
|
+
provisionerId: row.provisionerId,
|
|
68
|
+
provisionedRunnerId: row.provisionedRunnerId,
|
|
69
|
+
labels: row.labels,
|
|
70
|
+
toolCapabilities: row.toolCapabilities,
|
|
71
|
+
toolCapabilitiesReportedAt: row.toolCapabilitiesReportedAt,
|
|
72
|
+
maxClaims: row.maxClaims,
|
|
73
|
+
claimsUsed: row.claimsUsed,
|
|
74
|
+
createdAt: row.createdAt,
|
|
75
|
+
updatedAt: row.updatedAt,
|
|
76
|
+
};
|
|
77
|
+
}
|