|
|
|
@ -1,6 +1,4 @@
|
|
|
|
|
#include "config.hpp"
|
|
|
|
|
#include "program.hpp"
|
|
|
|
|
#include "runner.hpp"
|
|
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <queue>
|
|
|
|
@ -9,8 +7,17 @@
|
|
|
|
|
#include <toml++/toml.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <wait.h>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
|
|
#include "host.hpp"
|
|
|
|
|
#include "rpc/server.h"
|
|
|
|
|
#include "rpc/this_handler.h"
|
|
|
|
|
#include "config.hpp"
|
|
|
|
|
#include "program.hpp"
|
|
|
|
|
#include "runner.hpp"
|
|
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
|
|
|
|
|
@ -31,24 +38,53 @@ sk::runner_backend detect_backend() {
|
|
|
|
|
return sk::runner_backend::BubbleWrap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void mainLoop(std::queue<sk::program>& programLists){
|
|
|
|
|
while(true){
|
|
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
|
std::time_t now_time = std::chrono::system_clock::to_time_t(now);
|
|
|
|
|
std::cout<<std::ctime(&now_time)<<" "<<programLists.size()<<std::endl;
|
|
|
|
|
if (programLists.size() == 1)
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
std::vector<sk::host> listsHosts = sk::config::loadHostsFromToml("../conf.toml");
|
|
|
|
|
std::priority_queue<sk::host> hosts(listsHosts.begin(), listsHosts.end());
|
|
|
|
|
|
|
|
|
|
std::queue<sk::program> programLists;
|
|
|
|
|
|
|
|
|
|
if (hosts.empty()) {
|
|
|
|
|
std::cerr << "Pas de host" << std::endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::queue<sk::program> queue;
|
|
|
|
|
queue.push(sk::program{"echo $(( 1 + 2 ))", "ghcr.io/moshell-lang/moshell:master"});
|
|
|
|
|
std::thread workerThread(mainLoop, std::ref(programLists));
|
|
|
|
|
|
|
|
|
|
rpc::server srv(9000);
|
|
|
|
|
|
|
|
|
|
srv.bind("add", [&hosts, &programLists](const std::string &prog, const std::string &image) {
|
|
|
|
|
programLists.push(sk::program{prog, image});
|
|
|
|
|
|
|
|
|
|
const sk::program ¤tProgram = programLists.front();
|
|
|
|
|
const sk::host ¤tHost = hosts.top();
|
|
|
|
|
sk::runner runner(detect_backend());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sk::runner runner(detect_backend());
|
|
|
|
|
while (!queue.empty()) {
|
|
|
|
|
const sk::program ¤t = queue.front();
|
|
|
|
|
sk::run_result res = runner.run_blocking(current);
|
|
|
|
|
sk::run_result res = runner.run_blocking(currentProgram);
|
|
|
|
|
std::cout << "out: " << res.out << "\n";
|
|
|
|
|
std::cout << "err: " << res.err << "\n";
|
|
|
|
|
queue.pop();
|
|
|
|
|
}
|
|
|
|
|
programLists.pop();
|
|
|
|
|
|
|
|
|
|
if (res.err != "") {
|
|
|
|
|
rpc::this_handler().respond_error(res.err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.out;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
srv.run();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|