joque
task orchestration library
records.hpp
Go to the documentation of this file.
1 #pragma once
23 
24 #include "run_result.hpp"
25 #include "task.hpp"
26 
27 #include <chrono>
28 #include <cstddef>
29 #include <functional>
30 #include <list>
31 #include <map>
32 #include <string>
33 #include <string_view>
34 #include <vector>
35 
36 namespace joque
37 {
38 
39 enum class run_status : uint8_t
40 {
41  OK,
42  SKIP,
43  DEPF,
44  FAIL,
45 };
46 
47 std::string_view to_sv( const run_status& s );
48 
49 using tp = std::chrono::time_point< std::chrono::system_clock >;
50 
54 struct run_record
55 {
57  std::reference_wrapper< const task > t;
58 
60  std::string name;
61 
63 
65  int retcode = 0;
66 
68  tp start = std::chrono::system_clock::now();
69 
71  tp end = std::chrono::system_clock::now();
72 
73  std::list< output_chunk > output;
74 };
75 
76 void map( std::convertible_to< run_record > auto& rec, auto&& f )
77 {
78  f( "t", rec.t );
79  f( "name", rec.name );
80  f( "status", rec.status );
81  f( "retcode", rec.retcode );
82  f( "start", rec.start );
83  f( "end", rec.end );
84  f( "output", rec.output );
85 }
86 
90 {
91  std::map< run_status, std::size_t > stats{
92  { run_status::OK, 0 },
93  { run_status::SKIP, 0 },
94  { run_status::DEPF, 0 },
95  { run_status::FAIL, 0 },
96  };
98  std::size_t total_count = 0;
100  std::vector< run_record > runs;
101 };
102 
103 std::chrono::seconds runtime_sum( const exec_record& erec );
104 
105 void map( std::convertible_to< exec_record > auto& rec, auto&& f )
106 {
107  for ( auto&& [k, v] : rec.stats )
108  f( to_sv( k ), v );
109  f( "total_count", rec.total_count );
110  f( "runs", rec.runs );
111 }
112 
113 } // namespace joque
MIT License.
Definition: dag.hpp:27
std::map< run_status, std::size_t > stats
Definition: records.hpp:91
run_status
Definition: records.hpp:40
run_status status
Definition: records.hpp:62
std::reference_wrapper< const task > t
Executed task.
Definition: records.hpp:57
std::chrono::time_point< std::chrono::system_clock > tp
Definition: records.hpp:49
std::string_view to_sv(const ekind &e)
std::string name
Full name of the task.
Definition: records.hpp:60
std::chrono::seconds runtime_sum(const exec_record &erec)
std::vector< run_record > runs
Run record for each finished task in the set.
Definition: records.hpp:100
tp end
End time of the execution.
Definition: records.hpp:71
std::size_t total_count
Total number of jobs.
Definition: records.hpp:98
std::list< output_chunk > output
Definition: records.hpp:73
Fun && f
Definition: task.hpp:93
tp start
Start time of the execution.
Definition: records.hpp:68
void map(std::convertible_to< run_record > auto &rec, auto &&f)
Definition: records.hpp:76
int retcode
Return code of the execution. Assumes that 0 means success.
Definition: records.hpp:65
Record of execution of entire task set.
Definition: records.hpp:90
Record storing information about a run of one task, produced during single execution once for each ta...
Definition: records.hpp:55