1 | | | import 'package:meta/meta.dart'; |
2 | | |
|
3 | | | /// Base statistics for worker. |
4 | | | class WorkerStat { |
5 | | 11 | WorkerStat._( |
6 | | | this.workerType, |
7 | | | this.workerHashCode, |
8 | | | this.isStopped, |
9 | | | this.workload, |
10 | | | this.maxWorkload, |
11 | | | this.totalWorkload, |
12 | | | this.totalErrors, |
13 | | | this.upTime, |
14 | | | this.idleTime); |
15 | | |
|
16 | | | /// Timestamp of this snapshot |
17 | | | final timestamp = DateTime.now().toUtc(); |
18 | | |
|
19 | | | /// The worker's runtime type. |
20 | | | final Type workerType; |
21 | | |
|
22 | | | /// The worker's hashCode. |
23 | | | final int workerHashCode; |
24 | | |
|
25 | | | /// Worker running flag. |
26 | | | final bool isStopped; |
27 | | |
|
28 | | | /// Current workload being processed by the worker. |
29 | | | final int workload; |
30 | | |
|
31 | | | /// Maximum concurrent workload processed by the worker. |
32 | | | final int maxWorkload; |
33 | | |
|
34 | | | /// Total workload processed by the worker. |
35 | | | final int totalWorkload; |
36 | | |
|
37 | | | /// Total errors raised during processing. |
38 | | | final int totalErrors; |
39 | | |
|
40 | | | /// The worker's up-time. |
41 | | | Duration upTime; |
42 | | |
|
43 | | | /// The worker's idle-time. |
44 | | | Duration idleTime; |
45 | | | } |
46 | | |
|
47 | | | extension WorkerStatsExt on Iterable<WorkerStat> { |
48 | | 0 | int get workload => fold<int>(0, (p, s) => p + s.workload); |
49 | | 0 | int get totalWorkload => fold<int>(0, (p, s) => p + s.totalWorkload); |
50 | | 0 | int get totalErrors => fold<int>(0, (p, s) => p + s.totalErrors); |
51 | | | } |
52 | | |
|
53 | | | @internal |
54 | | | extension WorkerStatImpl on WorkerStat { |
55 | | 11 | static WorkerStat create( |
56 | | | Type workerType, |
57 | | | int workerHashCode, |
58 | | | bool isStopped, |
59 | | | int workload, |
60 | | | int maxWorkload, |
61 | | | int totalWorkload, |
62 | | | int totalErrors, |
63 | | | Duration upTime, |
64 | | | Duration idleTime) => |
65 | | 11 | WorkerStat._(workerType, workerHashCode, isStopped, workload, maxWorkload, |
66 | | | totalWorkload, totalErrors, upTime, idleTime); |
67 | | | } |