@@ -22,16 +22,16 @@ public JobRunner(JobInfo job)
22
22
{
23
23
this . JobInfo = job ;
24
24
}
25
-
25
+
26
26
public async Task < CloudJob > RunOnCloudAsync ( Project project , Action < string > progressReporting , System . Threading . CancellationToken token )
27
27
{
28
-
28
+
29
29
CloudJob cloudJob = null ;
30
30
try
31
31
{
32
32
cloudJob = await ScheduleCloudJobAsync ( project , this . Job , progressReporting , token ) ;
33
33
progressReporting ? . Invoke ( cloudJob . Status . Status . ToString ( ) ) ;
34
- LogHelper . LogInfo ( $ "A new cloud job { cloudJob . Id } is started in project { project . Name } ") ;
34
+ LogHelper . LogInfo ( $ "A new cloud job { cloudJob . Id } is started in project { project . Name } ") ;
35
35
}
36
36
catch ( Exception e )
37
37
{
@@ -61,7 +61,7 @@ public static async Task<Job> UploadJobAssetsAsync(
61
61
{
62
62
63
63
// check if all cloud path artifacts are within the same project
64
- var invalidCloudAssets = job . Arguments . SelectMany ( _ => _ . OfType < JobPathArgument > ( ) ) . Where ( _ => _ . IsAssetUploaded ( ) && _ . CloudProjectSlug ( ) != project . Slug ) . Select ( _=> $ "{ _ . ToUserFriendlyString ( true ) } ") . Distinct ( ) ;
64
+ var invalidCloudAssets = job . Arguments . SelectMany ( _ => _ . OfType < JobPathArgument > ( ) ) . Where ( _ => _ . IsAssetUploaded ( ) && _ . CloudProjectSlug ( ) != project . Slug ) . Select ( _ => $ "{ _ . ToUserFriendlyString ( true ) } ") . Distinct ( ) ;
65
65
if ( invalidCloudAssets . Any ( ) )
66
66
{
67
67
var error = $ "Following cloud assets cannot be uploaded to project { project . Slug } :\n \n { string . Join ( Environment . NewLine , invalidCloudAssets ) } ";
@@ -76,7 +76,8 @@ public static async Task<Job> UploadJobAssetsAsync(
76
76
// upload artifacts
77
77
if ( ! string . IsNullOrEmpty ( tempProjectDir ) )
78
78
{
79
- Action < int > updateMessageProgress = ( int p ) => {
79
+ Action < int > updateMessageProgress = ( int p ) =>
80
+ {
80
81
progressLogAction ? . Invoke ( $ "Preparing: [{ p } %]") ;
81
82
} ;
82
83
await Helper . UploadDirectoryAsync ( project , tempProjectDir , updateMessageProgress , cancellationToken ) ;
@@ -90,7 +91,7 @@ public static async Task<Job> UploadJobAssetsAsync(
90
91
LogHelper . LogInfo ( $ "Canceled by user") ;
91
92
return null ;
92
93
}
93
-
94
+
94
95
// update Artifact to cloud's relative path after uploaded.
95
96
var newJob = UpdateArtifactPath ( project . Slug , job , subfolderPath ) ;
96
97
@@ -124,7 +125,7 @@ private async Task<CloudJob> ScheduleCloudJobAsync(
124
125
125
126
// Upload artifacts
126
127
var newJob = await UploadJobAssetsAsync ( project , job , this . JobInfo . SubFolderPath , progressLogAction , cancellationToken ) ;
127
-
128
+
128
129
// create a new Simulation
129
130
var api = new JobsApi ( ) ;
130
131
progressLogAction ? . Invoke ( $ "Start running.") ;
@@ -174,13 +175,23 @@ public string RunOnLocalMachine(string workFolder, int workerNum, bool silentMod
174
175
175
176
var workName = this . Job . Name ?? "Unnamed" ;
176
177
workName = new String ( workName . Where ( c => char . IsLetterOrDigit ( c ) ) . ToArray ( ) ) ;
177
-
178
+
178
179
var workDir = workFolder ;
179
- if ( ! string . IsNullOrEmpty ( this . JobInfo . SubFolderPath ) )
180
+ if ( ! string . IsNullOrEmpty ( this . JobInfo . SubFolderPath ) )
180
181
workDir = Path . Combine ( workDir , this . JobInfo . SubFolderPath ) ;
181
182
workDir = Path . GetFullPath ( workDir ) ;
182
183
if ( Directory . Exists ( workDir ) )
183
- System . IO . Directory . Delete ( workDir , true ) ;
184
+ {
185
+ try
186
+ {
187
+ System . IO . Directory . Delete ( workDir , true ) ;
188
+ }
189
+ catch ( Exception e )
190
+ {
191
+ throw new ArgumentException ( $ "Failed to clean up the working folder: { workDir } . Please remove it manually!\n { e } ") ;
192
+ }
193
+ }
194
+
184
195
Directory . CreateDirectory ( workDir ) ;
185
196
186
197
var recipeOwner = this . JobInfo . RecipeOwner ;
@@ -189,7 +200,7 @@ public string RunOnLocalMachine(string workFolder, int workerNum, bool silentMod
189
200
190
201
var localArgs = this . Job . Arguments ;
191
202
var localArg = new LocalRunArguments ( localArgs . FirstOrDefault ( ) ) ; //TODO: ignore parametric runs for now
192
-
203
+
193
204
//localArg.Validate(userRecipe);
194
205
var inputJson = localArg . SaveToFolder ( workDir ) ; //save args to input.json file
195
206
@@ -236,7 +247,7 @@ public static RunStatusEnum CheckLocalJobStatus(string workDir)
236
247
{
237
248
//"C:\Users\mingo\simulation\Unnamed\Unnamed\__logs__\status.json"
238
249
var logDir = Directory . GetDirectories ( workDir , "*__logs__*" , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
239
-
250
+
240
251
var statusFile = Path . Combine ( logDir , "status.json" ) ;
241
252
if ( ! File . Exists ( statusFile ) )
242
253
return RunStatusEnum . Unknown ;
@@ -249,7 +260,7 @@ public static RunStatusEnum CheckLocalJobStatus(string workDir)
249
260
return RunStatusEnum . Unknown ;
250
261
251
262
var st = statusToken . ToObject < RunStatusEnum > ( ) ;
252
-
263
+
253
264
if ( st == RunStatusEnum . Succeeded || st == RunStatusEnum . Failed )
254
265
return st ;
255
266
else
@@ -286,7 +297,7 @@ public static string GetJobErrors(string workDir)
286
297
private static string CheckRecipeInProject ( string recipeSource , Project project )
287
298
{
288
299
var found = Helper . GetRecipeFromRecipeSourceURL ( recipeSource , out var recOwner , out var recName , out var recVersion ) ;
289
- if ( ! found )
300
+ if ( ! found )
290
301
{
291
302
LogHelper . LogThrowError ( $ "CheckRecipeInProject: invalid recipe source { recipeSource } ") ;
292
303
}
@@ -448,14 +459,14 @@ private static Job UpdateArtifactPath(string projSlug, Job job, string subFolder
448
459
}
449
460
}
450
461
451
-
462
+
452
463
453
464
}
454
465
455
466
return newJob ;
456
467
}
457
468
458
-
469
+
459
470
460
471
461
472
0 commit comments