feat: implement MoloApp plans 01-15 with integration
Full C++23 framework tree: runtime, observability, security, data, app, realtime, supervisor, clients, CLI, example plus enterprise tenancy, audit, operability, governance, supplychain. Postgres via docker compose for tests.
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
#include "Jobs.hpp"
|
||||
|
||||
#include "Caps.hpp"
|
||||
|
||||
namespace molo::example::fw {
|
||||
|
||||
void Supervisor::add_worker(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
if (!workers_.count(name) && workers_.size() >= caps::kMaxWorkers) return;
|
||||
workers_[name] = WorkerInfo{name, false, 0};
|
||||
}
|
||||
|
||||
bool Supervisor::start(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = workers_.find(name);
|
||||
if (it == workers_.end()) return false;
|
||||
it->second.running = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Supervisor::stop(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = workers_.find(name);
|
||||
if (it == workers_.end()) return false;
|
||||
it->second.running = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Supervisor::restart(const std::string& name) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = workers_.find(name);
|
||||
if (it == workers_.end()) return false;
|
||||
it->second.running = true;
|
||||
++it->second.restarts;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<WorkerInfo> Supervisor::status() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
std::vector<WorkerInfo> out;
|
||||
for (const auto& [k, v] : workers_) out.push_back(v);
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string TaskQueue::enqueue(const std::string& kind,
|
||||
const std::string& payload, long delay_sec) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
if (tasks_.size() >= caps::kMaxTasks) return "";
|
||||
std::string id = "task-" + std::to_string(next_id_++);
|
||||
TaskInfo t{id, kind, payload,
|
||||
delay_sec > 0 ? "delayed" : "queued", 0};
|
||||
tasks_[id] = t;
|
||||
return id;
|
||||
}
|
||||
|
||||
bool TaskQueue::cancel(const std::string& id) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = tasks_.find(id);
|
||||
if (it == tasks_.end()) return false;
|
||||
it->second.state = "cancelled";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TaskQueue::retry(const std::string& id) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = tasks_.find(id);
|
||||
if (it == tasks_.end()) return false;
|
||||
++it->second.attempts;
|
||||
it->second.state = "queued";
|
||||
return true;
|
||||
}
|
||||
|
||||
void TaskQueue::run_inline(TaskInfo& task) {
|
||||
task.state = "done";
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
auto it = tasks_.find(task.id);
|
||||
if (it != tasks_.end()) it->second.state = "done";
|
||||
}
|
||||
|
||||
std::vector<TaskInfo> TaskQueue::list() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
std::vector<TaskInfo> out;
|
||||
for (const auto& [k, v] : tasks_) out.push_back(v);
|
||||
return out;
|
||||
}
|
||||
|
||||
ReplEntry ReplicationLog::append(const std::string& object,
|
||||
const std::string& data) {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
ReplEntry e;
|
||||
e.seq = entries_.size() + 1;
|
||||
e.object = object;
|
||||
e.data = data;
|
||||
e.resolution = "last-writer-wins";
|
||||
if (entries_.size() < caps::kMaxReplEntries) entries_.push_back(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
std::vector<ReplEntry> ReplicationLog::since(unsigned long seq) const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
std::vector<ReplEntry> out;
|
||||
for (const auto& e : entries_) {
|
||||
if (e.seq > seq) out.push_back(e);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned long ReplicationLog::latest() const {
|
||||
std::lock_guard<std::mutex> lock(mu_);
|
||||
return entries_.size();
|
||||
}
|
||||
|
||||
} // namespace molo::example::fw
|
||||
Reference in New Issue
Block a user