@shipfox/api-workflows 11.0.0 → 12.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 +8 -8
- package/CHANGELOG.md +100 -0
- package/README.md +75 -0
- package/dist/core/agent-defaults.d.ts +2 -1
- package/dist/core/agent-defaults.d.ts.map +1 -1
- package/dist/core/agent-defaults.js.map +1 -1
- package/dist/core/checkout.d.ts +7 -21
- package/dist/core/checkout.d.ts.map +1 -1
- package/dist/core/checkout.js +122 -41
- package/dist/core/checkout.js.map +1 -1
- package/dist/core/entities/job-execution.d.ts +8 -0
- package/dist/core/entities/job-execution.d.ts.map +1 -1
- package/dist/core/entities/job-execution.js +13 -1
- package/dist/core/entities/job-execution.js.map +1 -1
- package/dist/core/entities/job-listener-event.d.ts +2 -0
- package/dist/core/entities/job-listener-event.d.ts.map +1 -1
- package/dist/core/entities/job-listener-event.js.map +1 -1
- package/dist/core/entities/step.d.ts +13 -3
- package/dist/core/entities/step.d.ts.map +1 -1
- package/dist/core/entities/step.js +6 -0
- package/dist/core/entities/step.js.map +1 -1
- package/dist/core/entities/workflow-run-attempt.d.ts +1 -0
- package/dist/core/entities/workflow-run-attempt.d.ts.map +1 -1
- package/dist/core/entities/workflow-run-attempt.js.map +1 -1
- package/dist/core/entities/workflow-run.d.ts +17 -0
- package/dist/core/entities/workflow-run.d.ts.map +1 -1
- package/dist/core/entities/workflow-run.js.map +1 -1
- package/dist/core/errors.d.ts +9 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +10 -5
- package/dist/core/errors.js.map +1 -1
- package/dist/core/job-execution.d.ts.map +1 -1
- package/dist/core/job-execution.js +14 -8
- package/dist/core/job-execution.js.map +1 -1
- package/dist/core/job-transition/decide-job-activation.d.ts +1 -0
- package/dist/core/job-transition/decide-job-activation.d.ts.map +1 -1
- package/dist/core/job-transition/decide-job-activation.js +1 -0
- package/dist/core/job-transition/decide-job-activation.js.map +1 -1
- package/dist/core/job-transition/derive-job-success.d.ts +1 -0
- package/dist/core/job-transition/derive-job-success.d.ts.map +1 -1
- package/dist/core/job-transition/derive-job-success.js +5 -8
- package/dist/core/job-transition/derive-job-success.js.map +1 -1
- package/dist/core/listener-execution-materialization.d.ts +6 -3
- package/dist/core/listener-execution-materialization.d.ts.map +1 -1
- package/dist/core/listener-execution-materialization.js +44 -6
- package/dist/core/listener-execution-materialization.js.map +1 -1
- package/dist/core/resolve-trigger-reference.d.ts +11 -0
- package/dist/core/resolve-trigger-reference.d.ts.map +1 -0
- package/dist/core/resolve-trigger-reference.js +39 -0
- package/dist/core/resolve-trigger-reference.js.map +1 -0
- package/dist/core/run-workflow.d.ts +1 -0
- package/dist/core/run-workflow.d.ts.map +1 -1
- package/dist/core/run-workflow.js +1 -0
- package/dist/core/run-workflow.js.map +1 -1
- package/dist/core/step-config/agent.d.ts +1 -2
- package/dist/core/step-config/agent.d.ts.map +1 -1
- package/dist/core/step-config/agent.js +22 -7
- package/dist/core/step-config/agent.js.map +1 -1
- package/dist/core/step-config/assemble-run-context.d.ts +19 -8
- package/dist/core/step-config/assemble-run-context.d.ts.map +1 -1
- package/dist/core/step-config/assemble-run-context.js +51 -19
- package/dist/core/step-config/assemble-run-context.js.map +1 -1
- package/dist/core/step-config/complete-step-dispatch-config.d.ts.map +1 -1
- package/dist/core/step-config/complete-step-dispatch-config.js +72 -4
- package/dist/core/step-config/complete-step-dispatch-config.js.map +1 -1
- package/dist/core/step-config/index.d.ts +1 -0
- package/dist/core/step-config/index.d.ts.map +1 -1
- package/dist/core/step-config/index.js +1 -0
- package/dist/core/step-config/index.js.map +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.d.ts +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.d.ts.map +1 -1
- package/dist/core/step-config/materialize-job-execution-steps.js +49 -8
- package/dist/core/step-config/materialize-job-execution-steps.js.map +1 -1
- package/dist/core/step-config/materialize-workflow-model.d.ts +3 -3
- package/dist/core/step-config/materialize-workflow-model.d.ts.map +1 -1
- package/dist/core/step-config/materialize-workflow-model.js +9 -5
- package/dist/core/step-config/materialize-workflow-model.js.map +1 -1
- package/dist/core/step-config/resolve-job-execution-name.d.ts +3 -3
- package/dist/core/step-config/resolve-job-execution-name.d.ts.map +1 -1
- package/dist/core/step-config/resolve-job-execution-name.js +24 -13
- package/dist/core/step-config/resolve-job-execution-name.js.map +1 -1
- package/dist/core/step-config/resolve-step-config.d.ts.map +1 -1
- package/dist/core/step-config/resolve-step-config.js +174 -9
- package/dist/core/step-config/resolve-step-config.js.map +1 -1
- package/dist/core/step-config/resolve-workflow-run-name.d.ts +19 -0
- package/dist/core/step-config/resolve-workflow-run-name.d.ts.map +1 -0
- package/dist/core/step-config/resolve-workflow-run-name.js +73 -0
- package/dist/core/step-config/resolve-workflow-run-name.js.map +1 -0
- package/dist/core/step-transition/decide-step-transition.js.map +1 -1
- package/dist/core/step-transition/evaluate-gate.d.ts +2 -1
- package/dist/core/step-transition/evaluate-gate.d.ts.map +1 -1
- package/dist/core/step-transition/evaluate-gate.js +5 -3
- package/dist/core/step-transition/evaluate-gate.js.map +1 -1
- package/dist/core/workflow-run-creation.d.ts +3 -0
- package/dist/core/workflow-run-creation.d.ts.map +1 -1
- package/dist/core/workflow-run-creation.js +22 -7
- package/dist/core/workflow-run-creation.js.map +1 -1
- package/dist/db/db.d.ts +278 -10
- package/dist/db/db.d.ts.map +1 -1
- package/dist/db/db.js +2 -0
- package/dist/db/db.js.map +1 -1
- package/dist/db/index.d.ts +3 -2
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +2 -1
- package/dist/db/index.js.map +1 -1
- package/dist/db/job-listener-events.d.ts +2 -0
- package/dist/db/job-listener-events.d.ts.map +1 -1
- package/dist/db/job-listener-events.js +1 -0
- package/dist/db/job-listener-events.js.map +1 -1
- package/dist/db/job-listeners.d.ts +2 -0
- package/dist/db/job-listeners.d.ts.map +1 -1
- package/dist/db/job-listeners.js +81 -21
- package/dist/db/job-listeners.js.map +1 -1
- package/dist/db/schema/job-executions.d.ts +3 -3
- package/dist/db/schema/job-executions.d.ts.map +1 -1
- package/dist/db/schema/job-executions.js +8 -4
- package/dist/db/schema/job-executions.js.map +1 -1
- package/dist/db/schema/job-listener-events.d.ts +20 -0
- package/dist/db/schema/job-listener-events.d.ts.map +1 -1
- package/dist/db/schema/job-listener-events.js +2 -0
- package/dist/db/schema/job-listener-events.js.map +1 -1
- package/dist/db/schema/step-attempts.js +2 -2
- package/dist/db/schema/step-attempts.js.map +1 -1
- package/dist/db/schema/steps.d.ts +4 -2
- package/dist/db/schema/steps.d.ts.map +1 -1
- package/dist/db/schema/steps.js +1 -1
- package/dist/db/schema/steps.js.map +1 -1
- package/dist/db/schema/workflow-run-attempts.d.ts +21 -2
- package/dist/db/schema/workflow-run-attempts.d.ts.map +1 -1
- package/dist/db/schema/workflow-run-attempts.js +2 -0
- package/dist/db/schema/workflow-run-attempts.js.map +1 -1
- package/dist/db/schema/workflow-run-counters.d.ts +43 -0
- package/dist/db/schema/workflow-run-counters.d.ts.map +1 -0
- package/dist/db/schema/workflow-run-counters.js +10 -0
- package/dist/db/schema/workflow-run-counters.js.map +1 -0
- package/dist/db/schema/workflow-runs.d.ts +54 -1
- package/dist/db/schema/workflow-runs.d.ts.map +1 -1
- package/dist/db/schema/workflow-runs.js +10 -2
- package/dist/db/schema/workflow-runs.js.map +1 -1
- package/dist/db/workflow-runs/job-executions.d.ts.map +1 -1
- package/dist/db/workflow-runs/job-executions.js +35 -14
- package/dist/db/workflow-runs/job-executions.js.map +1 -1
- package/dist/db/workflow-runs/jobs.d.ts +2 -0
- package/dist/db/workflow-runs/jobs.d.ts.map +1 -1
- package/dist/db/workflow-runs/jobs.js +9 -5
- package/dist/db/workflow-runs/jobs.js.map +1 -1
- package/dist/db/workflow-runs/queries.d.ts +51 -0
- package/dist/db/workflow-runs/queries.d.ts.map +1 -1
- package/dist/db/workflow-runs/queries.js +82 -2
- package/dist/db/workflow-runs/queries.js.map +1 -1
- package/dist/db/workflow-runs/run-create.d.ts +1 -0
- package/dist/db/workflow-runs/run-create.d.ts.map +1 -1
- package/dist/db/workflow-runs/run-create.js +159 -32
- package/dist/db/workflow-runs/run-create.js.map +1 -1
- package/dist/db/workflow-runs/run-rerun.d.ts.map +1 -1
- package/dist/db/workflow-runs/run-rerun.js +13 -5
- package/dist/db/workflow-runs/run-rerun.js.map +1 -1
- package/dist/db/workflow-runs/shared.d.ts +1 -0
- package/dist/db/workflow-runs/shared.d.ts.map +1 -1
- package/dist/db/workflow-runs/shared.js +2 -1
- package/dist/db/workflow-runs/shared.js.map +1 -1
- package/dist/db/workflow-runs/steps.js +3 -3
- package/dist/db/workflow-runs/steps.js.map +1 -1
- package/dist/db/workflow-runs.d.ts +4 -3
- package/dist/db/workflow-runs.d.ts.map +1 -1
- package/dist/db/workflow-runs.js +3 -2
- package/dist/db/workflow-runs.js.map +1 -1
- package/dist/metrics/instance.d.ts +1 -0
- package/dist/metrics/instance.d.ts.map +1 -1
- package/dist/metrics/instance.js +9 -0
- package/dist/metrics/instance.js.map +1 -1
- package/dist/presentation/dto/checkout-token.d.ts +1 -0
- package/dist/presentation/dto/checkout-token.d.ts.map +1 -1
- package/dist/presentation/dto/checkout-token.js +1 -0
- package/dist/presentation/dto/checkout-token.js.map +1 -1
- package/dist/presentation/dto/index.d.ts +1 -1
- package/dist/presentation/dto/index.d.ts.map +1 -1
- package/dist/presentation/dto/index.js +1 -1
- package/dist/presentation/dto/index.js.map +1 -1
- package/dist/presentation/dto/step.d.ts.map +1 -1
- package/dist/presentation/dto/step.js +2 -2
- package/dist/presentation/dto/step.js.map +1 -1
- package/dist/presentation/dto/workflow-run.d.ts +3 -1
- package/dist/presentation/dto/workflow-run.d.ts.map +1 -1
- package/dist/presentation/dto/workflow-run.js +34 -0
- package/dist/presentation/dto/workflow-run.js.map +1 -1
- package/dist/presentation/inter-module.d.ts.map +1 -1
- package/dist/presentation/inter-module.js +31 -3
- package/dist/presentation/inter-module.js.map +1 -1
- package/dist/presentation/routes/checkout-token.d.ts +1 -1
- package/dist/presentation/routes/checkout-token.d.ts.map +1 -1
- package/dist/presentation/routes/checkout-token.js +32 -20
- package/dist/presentation/routes/checkout-token.js.map +1 -1
- package/dist/presentation/routes/leased-step.d.ts +2 -0
- package/dist/presentation/routes/leased-step.d.ts.map +1 -1
- package/dist/presentation/routes/leased-step.js +2 -1
- package/dist/presentation/routes/leased-step.js.map +1 -1
- package/dist/presentation/routes/list-runs.d.ts.map +1 -1
- package/dist/presentation/routes/list-runs.js +9 -3
- package/dist/presentation/routes/list-runs.js.map +1 -1
- package/dist/presentation/routes/project-access.d.ts +1 -0
- package/dist/presentation/routes/project-access.d.ts.map +1 -1
- package/dist/presentation/routes/report-step.d.ts.map +1 -1
- package/dist/presentation/routes/report-step.js +9 -2
- package/dist/presentation/routes/report-step.js.map +1 -1
- package/dist/presentation/subscribers/on-job-steps-settled.js +1 -1
- package/dist/presentation/subscribers/on-job-steps-settled.js.map +1 -1
- package/dist/presentation/subscribers/on-runner-job-claimed.d.ts.map +1 -1
- package/dist/presentation/subscribers/on-runner-job-claimed.js +21 -0
- package/dist/presentation/subscribers/on-runner-job-claimed.js.map +1 -1
- package/dist/temporal/activities/index.d.ts.map +1 -1
- package/dist/temporal/activities/index.js +2 -1
- package/dist/temporal/activities/index.js.map +1 -1
- package/dist/temporal/activities/orchestration-activities.d.ts +1 -0
- package/dist/temporal/activities/orchestration-activities.d.ts.map +1 -1
- package/dist/temporal/activities/orchestration-activities.js.map +1 -1
- package/dist/temporal/constants.d.ts +1 -0
- package/dist/temporal/constants.d.ts.map +1 -1
- package/dist/temporal/constants.js +1 -0
- package/dist/temporal/constants.js.map +1 -1
- package/dist/temporal/index.d.ts +1 -1
- package/dist/temporal/index.d.ts.map +1 -1
- package/dist/temporal/index.js +1 -1
- package/dist/temporal/index.js.map +1 -1
- package/dist/temporal/workflows/index.bundle.js +82 -43
- package/dist/temporal/workflows/index.d.ts +1 -1
- package/dist/temporal/workflows/index.d.ts.map +1 -1
- package/dist/temporal/workflows/index.js +1 -1
- package/dist/temporal/workflows/index.js.map +1 -1
- package/dist/temporal/workflows/job-execution-orchestration.d.ts +5 -0
- package/dist/temporal/workflows/job-execution-orchestration.d.ts.map +1 -1
- package/dist/temporal/workflows/job-execution-orchestration.js +77 -43
- package/dist/temporal/workflows/job-execution-orchestration.js.map +1 -1
- package/dist/temporal/workflows/test-env.d.ts +5 -1
- package/dist/temporal/workflows/test-env.d.ts.map +1 -1
- package/dist/temporal/workflows/test-env.js +32 -11
- package/dist/temporal/workflows/test-env.js.map +1 -1
- package/dist/tsconfig.test.tsbuildinfo +1 -1
- package/drizzle/0000_initial.sql +14 -2
- package/drizzle/0001_windy_sunfire.sql +1 -0
- package/drizzle/meta/0000_snapshot.json +93 -1
- package/drizzle/meta/0001_snapshot.json +1711 -0
- package/drizzle/meta/_journal.json +2 -2
- package/package.json +21 -21
- package/src/core/agent-defaults.ts +2 -1
- package/src/core/checkout.test.ts +378 -67
- package/src/core/checkout.ts +142 -59
- package/src/core/entities/job-execution.test.ts +21 -0
- package/src/core/entities/job-execution.ts +24 -0
- package/src/core/entities/job-listener-event.ts +3 -0
- package/src/core/entities/step.ts +15 -3
- package/src/core/entities/workflow-run-attempt.ts +1 -0
- package/src/core/entities/workflow-run.ts +16 -0
- package/src/core/errors.ts +21 -7
- package/src/core/job-execution.ts +27 -4
- package/src/core/job-transition/decide-job-activation.test.ts +4 -0
- package/src/core/job-transition/decide-job-activation.ts +2 -0
- package/src/core/job-transition/derive-job-success.test.ts +12 -0
- package/src/core/job-transition/derive-job-success.ts +6 -9
- package/src/core/listener-execution-materialization.test.ts +2 -0
- package/src/core/listener-execution-materialization.ts +57 -11
- package/src/core/resolve-trigger-reference.test.ts +160 -0
- package/src/core/resolve-trigger-reference.ts +53 -0
- package/src/core/run-workflow.ts +2 -0
- package/src/core/step-config/agent.ts +29 -12
- package/src/core/step-config/assemble-run-context.test.ts +149 -6
- package/src/core/step-config/assemble-run-context.ts +87 -25
- package/src/core/step-config/complete-step-dispatch-config.test.ts +125 -2
- package/src/core/step-config/complete-step-dispatch-config.ts +83 -1
- package/src/core/step-config/index.ts +7 -0
- package/src/core/step-config/materialize-job-execution-steps.test.ts +250 -1
- package/src/core/step-config/materialize-job-execution-steps.ts +57 -10
- package/src/core/step-config/materialize-workflow-model.test.ts +212 -4
- package/src/core/step-config/materialize-workflow-model.ts +33 -28
- package/src/core/step-config/resolve-job-execution-name.test.ts +37 -15
- package/src/core/step-config/resolve-job-execution-name.ts +30 -15
- package/src/core/step-config/resolve-step-config.ts +175 -10
- package/src/core/step-config/resolve-workflow-run-name.test.ts +115 -0
- package/src/core/step-config/resolve-workflow-run-name.ts +108 -0
- package/src/core/step-transition/decide-step-transition.ts +2 -2
- package/src/core/step-transition/evaluate-gate.test.ts +8 -0
- package/src/core/step-transition/evaluate-gate.ts +8 -1
- package/src/core/workflow-run-creation.test.ts +7 -4
- package/src/core/workflow-run-creation.ts +13 -7
- package/src/db/db.ts +2 -0
- package/src/db/index.ts +6 -0
- package/src/db/job-listener-events.test.ts +19 -0
- package/src/db/job-listener-events.ts +3 -0
- package/src/db/job-listeners.test.ts +187 -5
- package/src/db/job-listeners.ts +122 -30
- package/src/db/schema/job-executions.ts +12 -5
- package/src/db/schema/job-listener-events.ts +3 -0
- package/src/db/schema/step-attempts.ts +2 -2
- package/src/db/schema/steps.ts +2 -1
- package/src/db/schema/workflow-run-attempts.ts +2 -0
- package/src/db/schema/workflow-run-counters.ts +13 -0
- package/src/db/schema/workflow-runs.ts +11 -2
- package/src/db/workflow-runs/job-executions.ts +37 -15
- package/src/db/workflow-runs/jobs.ts +17 -4
- package/src/db/workflow-runs/queries.test.ts +206 -0
- package/src/db/workflow-runs/queries.ts +146 -2
- package/src/db/workflow-runs/run-create.test.ts +606 -8
- package/src/db/workflow-runs/run-create.ts +185 -40
- package/src/db/workflow-runs/run-rerun.test.ts +61 -2
- package/src/db/workflow-runs/run-rerun.ts +15 -5
- package/src/db/workflow-runs/shared.ts +2 -0
- package/src/db/workflow-runs/steps.ts +3 -3
- package/src/db/workflow-runs.ts +7 -0
- package/src/metrics/instance.ts +14 -0
- package/src/presentation/dto/checkout-token.test.ts +19 -9
- package/src/presentation/dto/checkout-token.ts +2 -1
- package/src/presentation/dto/index.ts +1 -1
- package/src/presentation/dto/job.test.ts +9 -0
- package/src/presentation/dto/step.test.ts +12 -0
- package/src/presentation/dto/step.ts +5 -2
- package/src/presentation/dto/workflow-run.ts +44 -2
- package/src/presentation/inter-module.test.ts +165 -0
- package/src/presentation/inter-module.ts +38 -4
- package/src/presentation/routes/checkout-token.test.ts +357 -142
- package/src/presentation/routes/checkout-token.ts +56 -26
- package/src/presentation/routes/get-run.test.ts +2 -0
- package/src/presentation/routes/get-step-secrets.test.ts +7 -2
- package/src/presentation/routes/leased-step.ts +9 -1
- package/src/presentation/routes/list-runs.test.ts +57 -0
- package/src/presentation/routes/list-runs.ts +8 -3
- package/src/presentation/routes/report-step.test.ts +25 -0
- package/src/presentation/routes/report-step.ts +10 -2
- package/src/presentation/subscribers/on-job-steps-settled.ts +1 -1
- package/src/presentation/subscribers/on-runner-job-claimed.test.ts +49 -0
- package/src/presentation/subscribers/on-runner-job-claimed.ts +22 -0
- package/src/temporal/activities/index.ts +1 -0
- package/src/temporal/activities/orchestration-activities.ts +1 -0
- package/src/temporal/constants.ts +1 -0
- package/src/temporal/index.ts +1 -0
- package/src/temporal/workflows/index.ts +1 -0
- package/src/temporal/workflows/job-execution-orchestration.test.ts +142 -6
- package/src/temporal/workflows/job-execution-orchestration.ts +99 -50
- package/src/temporal/workflows/run-orchestration.test.ts +1 -1
- package/src/temporal/workflows/test-env.ts +50 -13
- package/test/factories/project.ts +2 -0
- package/test/factories/workflow-model.ts +80 -26
- package/test/factories/workflow-run.ts +4 -1
- package/test/fixtures/agent-inter-module.ts +2 -1
- package/test/fixtures/job-with-steps.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/drizzle/0001_agent_tool_materialization.sql +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import {WORKFLOW_RUN_JOB_PREVIEW_LIMIT} from '@shipfox/api-workflows-dto';
|
|
1
2
|
import {
|
|
2
3
|
paginateTimestampIdRows,
|
|
3
4
|
type TimestampIdCursor,
|
|
4
5
|
timestampIdCursorWhere,
|
|
5
6
|
} from '@shipfox/node-drizzle';
|
|
6
7
|
import {and, asc, count, desc, eq, gte, lte, type SQL, sql} from 'drizzle-orm';
|
|
8
|
+
import type {JobStatus} from '#core/entities/job.js';
|
|
7
9
|
import type {
|
|
8
10
|
JobExecutionDetail,
|
|
9
11
|
StepDetail,
|
|
@@ -44,6 +46,15 @@ export interface ListWorkflowRunsResult {
|
|
|
44
46
|
filteredTotalCount: number | null;
|
|
45
47
|
}
|
|
46
48
|
|
|
49
|
+
/** A run-list job glyph: enough to draw and label it, none of its steps. */
|
|
50
|
+
export interface WorkflowRunJobSummary {
|
|
51
|
+
id: string;
|
|
52
|
+
key: string;
|
|
53
|
+
name: string | null;
|
|
54
|
+
status: JobStatus;
|
|
55
|
+
position: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
47
58
|
export interface WorkflowRunAggregates {
|
|
48
59
|
status: Array<{value: WorkflowRunStatus; count: number}>;
|
|
49
60
|
triggerSource: Array<{value: string; count: number}>;
|
|
@@ -191,6 +202,132 @@ export async function listWorkflowRuns(
|
|
|
191
202
|
};
|
|
192
203
|
}
|
|
193
204
|
|
|
205
|
+
/** The run whose jobs to fetch, pinned to the attempt the caller already read. */
|
|
206
|
+
export interface WorkflowRunJobSummaryTarget {
|
|
207
|
+
id: string;
|
|
208
|
+
currentAttempt: number;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A page row's jobs: a bounded slice to draw, and totals describing all of them.
|
|
213
|
+
*
|
|
214
|
+
* The preview is what a row can show; `statusCounts` is what it can say. Keeping the counts
|
|
215
|
+
* server-side is what lets a row report a failure that sits past the preview.
|
|
216
|
+
*/
|
|
217
|
+
export interface WorkflowRunJobsSummary {
|
|
218
|
+
preview: WorkflowRunJobSummary[];
|
|
219
|
+
statusCounts: WorkflowRunJobStatusCount[];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface WorkflowRunJobStatusCount {
|
|
223
|
+
status: JobStatus;
|
|
224
|
+
count: number;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Jobs for a page of runs, keyed by run id.
|
|
229
|
+
*
|
|
230
|
+
* Issued once per page rather than once per run: the run list is the one surface that needs
|
|
231
|
+
* every run's jobs at once, and a per-row query would put 50 round trips behind it.
|
|
232
|
+
*
|
|
233
|
+
* Both reads are bounded by the page, not by workflow size. A workflow has no job limit and
|
|
234
|
+
* this list polls while runs are active, so returning every job of every row would let one
|
|
235
|
+
* large workflow decide how much the endpoint moves every four seconds. The preview is cut
|
|
236
|
+
* per run in the database, and everything past it is described by a grouped count instead.
|
|
237
|
+
*
|
|
238
|
+
* The attempt comes from the caller's own read rather than from a second look at
|
|
239
|
+
* `current_attempt`. Re-reading it here would let a re-run landing between the queries pair
|
|
240
|
+
* attempt 1's run metadata with attempt 2's jobs, and the row would report a status its strip
|
|
241
|
+
* contradicts.
|
|
242
|
+
*
|
|
243
|
+
* The two reads share one repeatable-read snapshot. They describe the same jobs at the same
|
|
244
|
+
* instant, and the strip combines them into a single glyph row, so under the default
|
|
245
|
+
* read-committed isolation a job settling between the statements would draw a pending glyph
|
|
246
|
+
* beside a summary counting it as failed. Sequential inside one transaction is the cost of
|
|
247
|
+
* that; at a four-second poll the extra round trip does not register.
|
|
248
|
+
*/
|
|
249
|
+
export async function listWorkflowRunJobSummaries(
|
|
250
|
+
runs: readonly WorkflowRunJobSummaryTarget[],
|
|
251
|
+
): Promise<Map<string, WorkflowRunJobsSummary>> {
|
|
252
|
+
const summaries = new Map<string, WorkflowRunJobsSummary>();
|
|
253
|
+
if (runs.length === 0) return summaries;
|
|
254
|
+
|
|
255
|
+
// A row-constructor IN over (run, attempt) so each pair is one lookup on the unique index
|
|
256
|
+
// that already covers those two columns.
|
|
257
|
+
const attemptPairs = sql.join(
|
|
258
|
+
runs.map((run) => sql`(${run.id}::uuid, ${run.currentAttempt})`),
|
|
259
|
+
sql`, `,
|
|
260
|
+
);
|
|
261
|
+
const attemptFilter = sql`(${workflowRunAttempts.workflowRunId}, ${workflowRunAttempts.attempt}) in (${attemptPairs})`;
|
|
262
|
+
|
|
263
|
+
const {previewRows, countRows} = await db().transaction(
|
|
264
|
+
async (tx) => {
|
|
265
|
+
const ranked = tx
|
|
266
|
+
.select({
|
|
267
|
+
workflowRunId: workflowRunAttempts.workflowRunId,
|
|
268
|
+
id: jobs.id,
|
|
269
|
+
key: jobs.key,
|
|
270
|
+
name: jobs.name,
|
|
271
|
+
status: jobs.status,
|
|
272
|
+
position: jobs.position,
|
|
273
|
+
rank: sql<number>`row_number() over (partition by ${workflowRunAttempts.workflowRunId} order by ${jobs.position} asc, ${jobs.id} asc)`.as(
|
|
274
|
+
'rank',
|
|
275
|
+
),
|
|
276
|
+
})
|
|
277
|
+
.from(jobs)
|
|
278
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
279
|
+
.where(attemptFilter)
|
|
280
|
+
.as('ranked');
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
previewRows: await tx
|
|
284
|
+
.select({
|
|
285
|
+
workflowRunId: ranked.workflowRunId,
|
|
286
|
+
id: ranked.id,
|
|
287
|
+
key: ranked.key,
|
|
288
|
+
name: ranked.name,
|
|
289
|
+
status: ranked.status,
|
|
290
|
+
position: ranked.position,
|
|
291
|
+
})
|
|
292
|
+
.from(ranked)
|
|
293
|
+
.where(lte(ranked.rank, WORKFLOW_RUN_JOB_PREVIEW_LIMIT))
|
|
294
|
+
.orderBy(asc(ranked.workflowRunId), asc(ranked.position), asc(ranked.id)),
|
|
295
|
+
countRows: await tx
|
|
296
|
+
.select({
|
|
297
|
+
workflowRunId: workflowRunAttempts.workflowRunId,
|
|
298
|
+
status: jobs.status,
|
|
299
|
+
count: count(),
|
|
300
|
+
})
|
|
301
|
+
.from(jobs)
|
|
302
|
+
.innerJoin(workflowRunAttempts, eq(jobs.workflowRunAttemptId, workflowRunAttempts.id))
|
|
303
|
+
.where(attemptFilter)
|
|
304
|
+
.groupBy(workflowRunAttempts.workflowRunId, jobs.status),
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
{isolationLevel: 'repeatable read', accessMode: 'read only'},
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
for (const {workflowRunId, ...summary} of previewRows) {
|
|
311
|
+
summaryFor(summaries, workflowRunId).preview.push(summary);
|
|
312
|
+
}
|
|
313
|
+
for (const {workflowRunId, status, count: statusCount} of countRows) {
|
|
314
|
+
summaryFor(summaries, workflowRunId).statusCounts.push({status, count: statusCount});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
return summaries;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function summaryFor(
|
|
321
|
+
summaries: Map<string, WorkflowRunJobsSummary>,
|
|
322
|
+
workflowRunId: string,
|
|
323
|
+
): WorkflowRunJobsSummary {
|
|
324
|
+
const existing = summaries.get(workflowRunId);
|
|
325
|
+
if (existing) return existing;
|
|
326
|
+
const created: WorkflowRunJobsSummary = {preview: [], statusCounts: []};
|
|
327
|
+
summaries.set(workflowRunId, created);
|
|
328
|
+
return created;
|
|
329
|
+
}
|
|
330
|
+
|
|
194
331
|
export async function listWorkflowRunsByProject(projectId: string): Promise<WorkflowRun[]> {
|
|
195
332
|
const result = await listWorkflowRuns({projectId, limit: 100});
|
|
196
333
|
return result.runs;
|
|
@@ -336,6 +473,7 @@ export async function getJobExecutionDetail(
|
|
|
336
473
|
): Promise<JobExecutionDetail | undefined> {
|
|
337
474
|
const rows = await db()
|
|
338
475
|
.select({
|
|
476
|
+
job: jobs,
|
|
339
477
|
jobExecution: jobExecutions,
|
|
340
478
|
step: steps,
|
|
341
479
|
stepAttempt: stepAttempts,
|
|
@@ -357,7 +495,10 @@ export async function getJobExecutionDetail(
|
|
|
357
495
|
const first = rows[0];
|
|
358
496
|
if (!first) return undefined;
|
|
359
497
|
|
|
360
|
-
const detail: JobExecutionDetail = {
|
|
498
|
+
const detail: JobExecutionDetail = {
|
|
499
|
+
...toJobExecution(first.jobExecution, first.job.name ?? first.job.key),
|
|
500
|
+
steps: [],
|
|
501
|
+
};
|
|
361
502
|
const stepById = new Map<string, StepDetail>();
|
|
362
503
|
for (const row of rows) {
|
|
363
504
|
if (row.step) {
|
|
@@ -407,7 +548,10 @@ function hydrateWorkflowRunDetail(
|
|
|
407
548
|
if (!row.jobExecution) continue;
|
|
408
549
|
let jobExecution = jobExecutionById.get(row.jobExecution.id);
|
|
409
550
|
if (!jobExecution) {
|
|
410
|
-
jobExecution = {
|
|
551
|
+
jobExecution = {
|
|
552
|
+
...toJobExecution(row.jobExecution, row.job.name ?? row.job.key),
|
|
553
|
+
steps: [],
|
|
554
|
+
};
|
|
411
555
|
jobExecutionById.set(row.jobExecution.id, jobExecution);
|
|
412
556
|
job.jobExecutions.push(jobExecution);
|
|
413
557
|
}
|