joque
task orchestration library
process.hpp
Go to the documentation of this file.
1 #pragma once
23 
24 #include "out.hpp"
25 #include "run_result.hpp"
26 #include "traits.hpp"
27 
28 #include <concepts>
29 #include <filesystem>
30 #include <optional>
31 #include <string>
32 #include <type_traits>
33 #include <vector>
34 
35 namespace joque
36 {
37 
44 struct process
45 {
47  std::vector< std::string > cmd;
49  std::vector< std::filesystem::path > input;
51  std::vector< std::filesystem::path > output;
52 
53  std::optional< std::filesystem::path > retcode_file; // TODO: write
54  // tests for this
55 
65  template < typename... Args >
66  [[nodiscard]] static process derive( Args&&... args );
67 
70  process add_output( std::filesystem::path p ) &&;
71 
72  process add_input( std::filesystem::path p ) &&;
73 
74  process set_retcode_file( std::filesystem::path p ) &&;
75 };
76 
80 template <>
82 {
85  [[nodiscard]] static inval_result is_invalidated( const process& p );
86 
89  [[nodiscard]] static run_result run( const task&, const process& p );
90 };
91 
92 template < typename... Args >
93 process process::derive( Args&&... args )
94 {
95  process res;
96 
97  auto f = [&]< typename T >( T&& thing ) {
98  if constexpr ( std::derived_from< std::decay_t< T >, out_tag > ) {
99  res.cmd.push_back( thing.p );
100  res.output.push_back( thing.p );
101  } else if constexpr ( std::same_as< std::decay_t< T >, std::filesystem::path > ) {
102  res.cmd.push_back( thing );
103  res.input.push_back( thing );
104  } else {
105  res.cmd.push_back( thing );
106  }
107  };
108  ( f( args ), ... );
109  return res;
110 }
111 
112 } // namespace joque
MIT License.
Definition: dag.hpp:27
Fun && f
Definition: task.hpp:93
Definition: run_result.hpp:65
TODO: hide this Result of single traits run call.
Definition: run_result.hpp:55
Single task that should be executed by the system.
Definition: task.hpp:49
static inval_result is_invalidated(const process &p)
Proces becames invalidated in case one of it's input files is more recent than any of output files.
static run_result run(const task &, const process &p)
Executes the process, captures output of both stdout and stderr.
Default job traits for all types.
Definition: traits.hpp:35
Baseclass for tagging system.
Definition: out.hpp:31
Job-friendly structure for definition of subprocess to be executed.
Definition: process.hpp:45
process add_output(std::filesystem::path p) &&
Adds an output path to the output files.
process set_retcode_file(std::filesystem::path p) &&
static process derive(Args &&... args)
Takes input command for process as any arguments and builds process instance out of those.
Definition: process.hpp:93
std::vector< std::filesystem::path > output
output files that shall be monitored for timestamps
Definition: process.hpp:51
process add_input(std::filesystem::path p) &&
std::vector< std::string > cmd
cmd for the process execution
Definition: process.hpp:47
std::optional< std::filesystem::path > retcode_file
Definition: process.hpp:53
std::vector< std::filesystem::path > input
input files that shall be monitored for changes
Definition: process.hpp:49