@@ -142,7 +142,7 @@ impl TryFrom<String> for Platform {
142
142
}
143
143
}
144
144
145
- #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash ) ]
145
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq , Hash , Serialize ) ]
146
146
pub enum ProcessCacheScope {
147
147
// Cached in all locations, regardless of success or failure.
148
148
Always ,
@@ -173,10 +173,14 @@ impl TryFrom<String> for ProcessCacheScope {
173
173
}
174
174
}
175
175
176
+ fn serialize_level < S : serde:: Serializer > ( level : & log:: Level , s : S ) -> Result < S :: Ok , S :: Error > {
177
+ s. serialize_str ( & level. to_string ( ) )
178
+ }
179
+
176
180
///
177
181
/// A process to be executed.
178
182
///
179
- #[ derive( Derivative , Clone , Debug , Eq ) ]
183
+ #[ derive( Derivative , Clone , Debug , Eq , Serialize ) ]
180
184
#[ derivative( PartialEq , Hash ) ]
181
185
pub struct Process {
182
186
///
@@ -216,6 +220,8 @@ pub struct Process {
216
220
#[ derivative( PartialEq = "ignore" , Hash = "ignore" ) ]
217
221
pub description : String ,
218
222
223
+ // NB: We serialize with a function to avoid adding a serde dep to the logging crate.
224
+ #[ serde( serialize_with = "serialize_level" ) ]
219
225
pub level : log:: Level ,
220
226
221
227
///
@@ -391,17 +397,40 @@ pub struct FallibleProcessResultWithPlatform {
391
397
392
398
/// Metadata for a ProcessResult corresponding to the REAPI `ExecutedActionMetadata` proto. This
393
399
/// conversion is lossy, but the interesting parts are preserved.
394
- #[ derive( Clone , Debug , Default , Eq , PartialEq ) ]
400
+ #[ derive( Clone , Debug , Eq , PartialEq ) ]
395
401
pub struct ProcessResultMetadata {
396
402
/// The time from starting to completion, including preparing the chroot and cleanup.
397
403
/// Corresponds to `worker_start_timestamp` and `worker_completed_timestamp` from
398
404
/// `ExecutedActionMetadata`.
405
+ ///
406
+ /// NB: This is optional because the REAPI does not guarantee that it is returned.
399
407
pub total_elapsed : Option < Duration > ,
408
+ /// The source of the result.
409
+ pub source : ProcessResultSource ,
400
410
}
401
411
402
412
impl ProcessResultMetadata {
403
- pub fn new ( total_elapsed : Option < Duration > ) -> Self {
404
- ProcessResultMetadata { total_elapsed }
413
+ pub fn new ( total_elapsed : Option < Duration > , source : ProcessResultSource ) -> Self {
414
+ ProcessResultMetadata {
415
+ total_elapsed,
416
+ source,
417
+ }
418
+ }
419
+
420
+ pub fn new_from_metadata ( metadata : ExecutedActionMetadata , source : ProcessResultSource ) -> Self {
421
+ let total_elapsed = match (
422
+ metadata. worker_start_timestamp ,
423
+ metadata. worker_completed_timestamp ,
424
+ ) {
425
+ ( Some ( started) , Some ( completed) ) => TimeSpan :: from_start_and_end ( & started, & completed, "" )
426
+ . map ( |span| span. duration )
427
+ . ok ( ) ,
428
+ _ => None ,
429
+ } ;
430
+ Self {
431
+ total_elapsed,
432
+ source,
433
+ }
405
434
}
406
435
407
436
/// How much faster a cache hit was than running the process again.
@@ -429,21 +458,6 @@ impl ProcessResultMetadata {
429
458
}
430
459
}
431
460
432
- impl From < ExecutedActionMetadata > for ProcessResultMetadata {
433
- fn from ( metadata : ExecutedActionMetadata ) -> Self {
434
- let total_elapsed = match (
435
- metadata. worker_start_timestamp ,
436
- metadata. worker_completed_timestamp ,
437
- ) {
438
- ( Some ( started) , Some ( completed) ) => TimeSpan :: from_start_and_end ( & started, & completed, "" )
439
- . map ( |span| span. duration )
440
- . ok ( ) ,
441
- _ => None ,
442
- } ;
443
- Self { total_elapsed }
444
- }
445
- }
446
-
447
461
impl From < ProcessResultMetadata > for ExecutedActionMetadata {
448
462
fn from ( metadata : ProcessResultMetadata ) -> ExecutedActionMetadata {
449
463
let ( total_start, total_end) = match metadata. total_elapsed {
@@ -470,6 +484,14 @@ impl From<ProcessResultMetadata> for ExecutedActionMetadata {
470
484
}
471
485
}
472
486
487
+ #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
488
+ pub enum ProcessResultSource {
489
+ RanLocally ,
490
+ RanRemotely ,
491
+ HitLocally ,
492
+ HitRemotely ,
493
+ }
494
+
473
495
#[ derive( Clone ) ]
474
496
pub struct Context {
475
497
workunit_store : WorkunitStore ,
0 commit comments