/// /// Copyright 2015-2017 Oliver Giles /// /// This file is part of Laminar /// /// Laminar is free software: you can redistribute it and/or modify /// it under the terms of the GNU General Public License as published by /// the Free Software Foundation, either version 3 of the License, or /// (at your option) any later version. /// /// Laminar is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with Laminar. If not, see /// #ifndef LAMINAR_RUN_H_ #define LAMINAR_RUN_H_ #include #include #include #include #include #include #include #include enum class RunState { UNKNOWN, PENDING, RUNNING, ABORTED, FAILED, SUCCESS }; std::string to_string(const RunState& rs); class Node; // Represents an execution of a job. Not much more than POD class Run { public: Run(); ~Run(); // copying this class would be asking for trouble... Run(const Run&) = delete; Run& operator=(const Run&) = delete; // executes the next script (if any), returning true if there is nothing // more to be done - in this case the caller should call complete() bool step(); // call this when all scripts are done to get the notifyCompletion callback void complete(); // adds a script to the queue of scripts to be executed by this run void addScript(std::string scriptPath, std::string scriptWorkingDir); // adds a script to the queue using the runDir as the scripts CWD void addScript(std::string script) { addScript(script, runDir); } // adds an environment file that will be sourced before this run void addEnv(std::string path); // aborts this run void abort(); // called when a process owned by this run has been reaped. The status // may be used to set the run's job status void reaped(int status); std::string reason() const; std::function notifyCompletion; std::shared_ptr node; RunState result; RunState lastResult; std::string laminarHome; std::string name; std::string runDir; std::string parentName; int parentBuild = 0; std::string reasonMsg; uint build = 0; std::string log; pid_t pid; int fd; std::unordered_map params; kj::Promise timeout = kj::NEVER_DONE; time_t queuedAt; time_t startedAt; private: struct Script { std::string path; std::string cwd; }; std::queue