@@ -23,63 +23,70 @@ export async function evaluateExpectationStateWaiting({
23
23
24
24
if ( trackedExp . session . assignedWorker ) {
25
25
try {
26
+ // First check if the Expectation depends on the fulfilled-status of another Expectation:
27
+ const isWaitingForOther = tracker . trackedExpectationAPI . isExpectationWaitingForOther ( trackedExp )
28
+
29
+ if ( isWaitingForOther ) {
30
+ // Not ready to start because it's waiting for another expectation to be fulfilled first
31
+ // Stay here in WAITING state:
32
+ tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
33
+ reason : {
34
+ user : `Waiting for "${ isWaitingForOther . exp . statusReport . label } "` ,
35
+ tech : `Waiting for "${ isWaitingForOther . exp . statusReport . label } "` ,
36
+ } ,
37
+ } )
38
+
39
+ return
40
+ }
41
+
26
42
// First, check if it is already fulfilled:
27
43
const fulfilled = await trackedExp . session . assignedWorker . worker . isExpectationFulfilled (
28
44
trackedExp . exp ,
29
45
false
30
46
)
31
47
if ( fulfilled . fulfilled ) {
32
48
// The expectation is already fulfilled:
49
+
33
50
tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
34
51
state : ExpectedPackageStatusAPI . WorkStatusState . FULFILLED ,
35
52
} )
36
53
if ( tracker . trackedExpectationAPI . onExpectationFulfilled ( trackedExp ) ) {
37
54
// Something was triggered, run again ASAP:
38
55
trackedExp . session . triggerOtherExpectationsAgain = true
39
56
}
40
- } else {
41
- const readyToStart = await tracker . trackedExpectationAPI . isExpectationReadyToStartWorkingOn (
42
- trackedExp . session . assignedWorker . worker ,
43
- trackedExp
44
- )
57
+ return
58
+ }
59
+ const readyToStart = await tracker . trackedExpectationAPI . isExpectationReadyToStartWorkingOn (
60
+ trackedExp . session . assignedWorker . worker ,
61
+ trackedExp
62
+ )
45
63
46
- const newStatus : Partial < TrackedExpectation [ 'status' ] > = { }
47
- {
48
- const sourceExists = readyToStart . ready || readyToStart . sourceExists
49
- if ( sourceExists !== undefined ) newStatus . sourceExists = sourceExists
50
- }
51
- {
52
- const isPlaceholder = readyToStart . ready ? false : readyToStart . isPlaceholder
53
- if ( isPlaceholder !== undefined ) newStatus . sourceIsPlaceholder = isPlaceholder
54
- }
64
+ const newStatus : Partial < TrackedExpectation [ 'status' ] > = { }
65
+ {
66
+ const sourceExists = readyToStart . ready || readyToStart . sourceExists
67
+ if ( sourceExists !== undefined ) newStatus . sourceExists = sourceExists
68
+ }
69
+ {
70
+ const isPlaceholder = readyToStart . ready ? false : readyToStart . isPlaceholder
71
+ if ( isPlaceholder !== undefined ) newStatus . sourceIsPlaceholder = isPlaceholder
72
+ }
55
73
56
- if ( readyToStart . ready ) {
57
- tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
58
- state : ExpectedPackageStatusAPI . WorkStatusState . READY ,
59
- reason : {
60
- user : 'About to start working..' ,
61
- tech : `About to start, was not fulfilled: ${ fulfilled . reason . tech } ` ,
62
- } ,
63
- status : newStatus ,
64
- } )
65
- } else {
66
- // Not ready to start
67
- if ( readyToStart . isWaitingForAnother ) {
68
- // Not ready to start because it's waiting for another expectation to be fulfilled first
69
- // Stay here in WAITING state:
70
- tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
71
- reason : readyToStart . reason ,
72
- status : newStatus ,
73
- } )
74
- } else {
75
- // Not ready to start because of some other reason (e.g. the source doesn't exist)
76
- // Stay here in WAITING state:
77
- tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
78
- reason : readyToStart . reason ,
79
- status : newStatus ,
80
- } )
81
- }
82
- }
74
+ if ( readyToStart . ready ) {
75
+ tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
76
+ state : ExpectedPackageStatusAPI . WorkStatusState . READY ,
77
+ reason : {
78
+ user : 'About to start working..' ,
79
+ tech : `About to start, was not fulfilled: ${ fulfilled . reason . tech } ` ,
80
+ } ,
81
+ status : newStatus ,
82
+ } )
83
+ } else {
84
+ // Not ready to start because of some reason (e.g. the source doesn't exist)
85
+ // Stay here in WAITING state:
86
+ tracker . trackedExpectationAPI . updateTrackedExpectationStatus ( trackedExp , {
87
+ reason : readyToStart . reason ,
88
+ status : newStatus ,
89
+ } )
83
90
}
84
91
} catch ( error ) {
85
92
// There was an error, clearly it's not ready to start
0 commit comments