@@ -5,7 +5,6 @@ import { RequestError } from "@octokit/request-error";
5
5
import type {
6
6
VariantAnalysis ,
7
7
VariantAnalysisScannedRepository ,
8
- VariantAnalysisStatus ,
9
8
} from "./shared/variant-analysis" ;
10
9
import {
11
10
isFinalVariantAnalysisStatus ,
@@ -18,6 +17,7 @@ import { sleep } from "../common/time";
18
17
import { getErrorMessage } from "../common/helpers-pure" ;
19
18
import type { App } from "../common/app" ;
20
19
import { showAndLogWarningMessage } from "../common/logging" ;
20
+ import type { QueryLanguage } from "../common/query-language" ;
21
21
22
22
export class VariantAnalysisMonitor extends DisposableObject {
23
23
// With a sleep of 5 seconds, the maximum number of attempts takes
@@ -37,9 +37,9 @@ export class VariantAnalysisMonitor extends DisposableObject {
37
37
private readonly shouldCancelMonitor : (
38
38
variantAnalysisId : number ,
39
39
) => Promise < boolean > ,
40
- private readonly getVariantAnalysisStatus : (
40
+ private readonly getVariantAnalysis : (
41
41
variantAnalysisId : number ,
42
- ) => VariantAnalysisStatus ,
42
+ ) => VariantAnalysis ,
43
43
) {
44
44
super ( ) ;
45
45
}
@@ -60,20 +60,28 @@ export class VariantAnalysisMonitor extends DisposableObject {
60
60
61
61
this . monitoringVariantAnalyses . add ( variantAnalysis . id ) ;
62
62
try {
63
- await this . _monitorVariantAnalysis ( variantAnalysis ) ;
63
+ await this . _monitorVariantAnalysis (
64
+ variantAnalysis . id ,
65
+ variantAnalysis . controllerRepo . id ,
66
+ variantAnalysis . executionStartTime ,
67
+ variantAnalysis . query . name ,
68
+ variantAnalysis . language ,
69
+ ) ;
64
70
} finally {
65
71
this . monitoringVariantAnalyses . delete ( variantAnalysis . id ) ;
66
72
}
67
73
}
68
74
69
75
private async _monitorVariantAnalysis (
70
- variantAnalysis : VariantAnalysis ,
76
+ variantAnalysisId : number ,
77
+ controllerRepoId : number ,
78
+ executionStartTime : number ,
79
+ queryName : string ,
80
+ language : QueryLanguage ,
71
81
) : Promise < void > {
72
- const variantAnalysisLabel = `${ variantAnalysis . query . name } (${
73
- variantAnalysis . language
74
- } ) [${ new Date ( variantAnalysis . executionStartTime ) . toLocaleString (
75
- env . language ,
76
- ) } ]`;
82
+ const variantAnalysisLabel = `${ queryName } (${ language } ) [${ new Date (
83
+ executionStartTime ,
84
+ ) . toLocaleString ( env . language ) } ]`;
77
85
78
86
let attemptCount = 0 ;
79
87
const scannedReposDownloaded : number [ ] = [ ] ;
@@ -83,16 +91,16 @@ export class VariantAnalysisMonitor extends DisposableObject {
83
91
while ( attemptCount <= VariantAnalysisMonitor . maxAttemptCount ) {
84
92
await sleep ( VariantAnalysisMonitor . sleepTime ) ;
85
93
86
- if ( await this . shouldCancelMonitor ( variantAnalysis . id ) ) {
94
+ if ( await this . shouldCancelMonitor ( variantAnalysisId ) ) {
87
95
return ;
88
96
}
89
97
90
98
let variantAnalysisSummary : ApiVariantAnalysis ;
91
99
try {
92
100
variantAnalysisSummary = await getVariantAnalysis (
93
101
this . app . credentials ,
94
- variantAnalysis . controllerRepo . id ,
95
- variantAnalysis . id ,
102
+ controllerRepoId ,
103
+ variantAnalysisId ,
96
104
) ;
97
105
} catch ( e ) {
98
106
const errorMessage = getErrorMessage ( e ) ;
@@ -123,15 +131,10 @@ export class VariantAnalysisMonitor extends DisposableObject {
123
131
continue ;
124
132
}
125
133
126
- // Get the current status of the variant analysis as known by the rest
127
- // of the app, because it may have been changed by the user and this code
128
- // may not be aware of it yet.
129
- const currentStatus = this . getVariantAnalysisStatus ( variantAnalysis . id ) ;
130
- variantAnalysis = mapUpdatedVariantAnalysis (
131
- {
132
- ...variantAnalysis ,
133
- status : currentStatus ,
134
- } ,
134
+ const variantAnalysis = mapUpdatedVariantAnalysis (
135
+ // Get the variant analysis as known by the rest of the app, because it may
136
+ // have been changed by the user and the monitors may not be aware of it yet.
137
+ this . getVariantAnalysis ( variantAnalysisId ) ,
135
138
variantAnalysisSummary ,
136
139
) ;
137
140
0 commit comments