-
Notifications
You must be signed in to change notification settings - Fork 6
/
StepList.ts
56 lines (48 loc) · 1.4 KB
/
StepList.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (C) 2023 Thirty Meter Telescope International Observatory
* SPDX-License-Identifier: Apache-2.0
*/
import type { Option, SequenceCommand } from '../../../models'
/**
* @category Sequencer Service
*/
export interface Step {
readonly id: string
readonly command: SequenceCommand
readonly status: StepStatus
readonly hasBreakpoint: boolean
}
/**
* @category Sequencer Service
*/
export class StepList {
constructor(readonly steps: Step[]) {}
toJSON() {
return this.steps
}
isPaused(): boolean {
const firstPendingStep = this.findFirstPendingStep()
return firstPendingStep !== undefined && firstPendingStep.hasBreakpoint
}
isFailed(): boolean {
const failedStep = this.steps.find((step) => step.status._type === 'Failure')
return failedStep !== undefined
}
private findFirstPendingStep(): Option<Step> {
return this.steps.find((step) => StepList.isPending(step))
}
private static isPending(step: Step): boolean {
return step.status._type === 'Pending'
}
}
export type StepStatusPending = { _type: 'Pending' }
export type StepStatusInFlight = { _type: 'InFlight' }
export type StepStatusSuccess = { _type: 'Success' }
export type StepStatusFailure = {
readonly _type: 'Failure'
readonly message: string
}
/**
* @category Sequencer Service
*/
export type StepStatus = StepStatusPending | StepStatusInFlight | StepStatusSuccess | StepStatusFailure