Arachne 1.0
Arachne - the perpetual stitcher of Wikidata entities.
Loading...
Searching...
No Matches
coordinator.hpp
Go to the documentation of this file.
1#ifndef ARACHNE_COORDINATOR_HPP
2#define ARACHNE_COORDINATOR_HPP
3
4#include <chrono>
5#include <cstdint>
6#include <filesystem>
7#include <optional>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace arachne::coordination {
13
26
27[[nodiscard]] std::string_view to_string(cocoon_status status) noexcept;
28[[nodiscard]] cocoon_status cocoon_status_from_string(std::string_view value);
29[[nodiscard]] bool
31
33 std::filesystem::path source_path;
34 std::filesystem::path inbox_root;
35 std::string submission_ref;
36 std::string title;
37 std::optional<std::string> supersedes;
38 std::uintmax_t max_payload_bytes = 64U * 1024U * 1024U;
39};
40
42 std::string envelope_id;
43 std::filesystem::path payload_ref;
44 std::string payload_sha256;
46 std::string submission_ref;
47 std::string title;
49 std::optional<std::string> accepted_by;
50 std::optional<std::string> supersedes;
52};
53
63
69
75
77 std::filesystem::path path;
78 std::string message;
79};
80
82public:
83 explicit operational_ledger(
84 std::filesystem::path database_path,
85 std::optional<std::filesystem::path> legacy_inbox_root = std::nullopt
86 );
88
93
96 std::string_view envelope_id, cocoon_status next,
97 std::string_view actor_ref, std::string_view reason = {}
98 );
99 [[nodiscard]] envelope_record get(std::string_view envelope_id) const;
102 history(std::string_view envelope_id) const;
103
104 void capture_inbox_baseline(const std::filesystem::path& inbox_root);
106 verify_inbox(const std::filesystem::path& inbox_root) const;
107
109 std::string_view envelope_id,
110 const std::filesystem::path& internal_queue_root,
111 std::optional<std::filesystem::path> legacy_inbox_root = std::nullopt
112 );
113
115 [[nodiscard]] bool
116 should_integrate(const accumulation_policy& policy) const;
117
119 std::string_view run_id, std::string_view graph_domain,
120 std::string_view logical_date, std::string_view configuration_sha256,
121 bool retry_failed = false, bool resume_running = false
122 );
124 std::string_view run_id,
125 const std::vector<std::string>& envelope_ids
126 );
128 product_run_inputs(std::string_view run_id) const;
130 std::string_view run_id, std::string_view manifest_ref
131 );
132 void finish_run(
133 std::string_view run_id, std::string_view status,
134 std::string_view manifest_ref = {}
135 );
136
137 [[nodiscard]] const std::filesystem::path& path() const noexcept;
138
139private:
140 struct implementation;
142 std::filesystem::path path_;
143 std::optional<std::filesystem::path> legacy_inbox_root_;
144};
145
146[[nodiscard]] bool path_is_within(
147 const std::filesystem::path& path,
148 const std::filesystem::path& possible_parent
149);
150
151void reject_inbox_deletion_target(
152 const std::filesystem::path& target, const std::filesystem::path& inbox_root
153);
154
156public:
158 const std::filesystem::path& lock_root, std::string_view graph_domain,
159 std::string_view run_id,
160 std::chrono::seconds stale_after = std::chrono::hours(6)
161 );
162 ~domain_lock();
163
164 domain_lock(const domain_lock&) = delete;
165 domain_lock& operator=(const domain_lock&) = delete;
166 domain_lock(domain_lock&& other) noexcept;
167 domain_lock& operator=(domain_lock&& other) noexcept;
168
169 [[nodiscard]] bool owns_lock() const noexcept;
170 void release();
171
172private:
173 std::filesystem::path directory_;
174 std::string ownership_token_;
175 bool owns_ = false;
176};
177
178} // namespace arachne::coordination
179
180#endif
domain_lock(const std::filesystem::path &lock_root, std::string_view graph_domain, std::string_view run_id, std::chrono::seconds stale_after=std::chrono::hours(6))
domain_lock(const domain_lock &)=delete
domain_lock(domain_lock &&other) noexcept
domain_lock & operator=(const domain_lock &)=delete
domain_lock & operator=(domain_lock &&other) noexcept
void bind_product_run_inputs(std::string_view run_id, const std::vector< std::string > &envelope_ids)
operational_ledger & operator=(operational_ledger &&)=delete
void finish_integrated_product_run(std::string_view run_id, std::string_view manifest_ref)
operational_ledger(const operational_ledger &)=delete
envelope_record transition(std::string_view envelope_id, cocoon_status next, std::string_view actor_ref, std::string_view reason={})
operational_ledger(std::filesystem::path database_path, std::optional< std::filesystem::path > legacy_inbox_root=std::nullopt)
envelope_record get(std::string_view envelope_id) const
envelope_record intake(const intake_request &request)
void capture_inbox_baseline(const std::filesystem::path &inbox_root)
accumulation_state accumulation() const
bool retire_queued_payload(std::string_view envelope_id, const std::filesystem::path &internal_queue_root, std::optional< std::filesystem::path > legacy_inbox_root=std::nullopt)
void finish_run(std::string_view run_id, std::string_view status, std::string_view manifest_ref={})
std::optional< std::filesystem::path > legacy_inbox_root_
std::vector< envelope_record > product_run_inputs(std::string_view run_id) const
std::vector< envelope_record > list(cocoon_status status) const
std::vector< verification_issue > verify_inbox(const std::filesystem::path &inbox_root) const
bool should_integrate(const accumulation_policy &policy) const
std::vector< state_event > history(std::string_view envelope_id) const
operational_ledger & operator=(const operational_ledger &)=delete
bool claim_logical_run(std::string_view run_id, std::string_view graph_domain, std::string_view logical_date, std::string_view configuration_sha256, bool retry_failed=false, bool resume_running=false)
operational_ledger(operational_ledger &&)=delete
std::unique_ptr< sqlite3, decltype(&sqlite3_close)> sqlite_handle
std::unique_ptr< sqlite3_stmt, decltype(&sqlite3_finalize)> statement_handle
std::string_view to_string(const cocoon_status status) noexcept
cocoon_status cocoon_status_from_string(const std::string_view value)
bool can_transition(const cocoon_status from, const cocoon_status to) noexcept
std::string sha256(std::span< const std::byte > bytes)
Definition crypto.cpp:209
std::string sha256_file(const std::filesystem::path &path)
Definition crypto.cpp:221
std::optional< std::string > supersedes
std::optional< std::string > accepted_by
std::optional< std::string > supersedes