resolves #52: timeout prevents .after script

Mark .after scripts as executing even after a timeout abort
pull/70/head
Oliver Giles 6 years ago
parent a2d30ad2ea
commit ab7be5a6c9

@ -587,7 +587,7 @@ void Laminar::notifyConfigChanged()
void Laminar::abortAll() {
for(std::shared_ptr<Run> run : activeJobs) {
run->abort();
run->abort(false);
}
}
@ -674,13 +674,13 @@ bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
run->addScript((cfgDir/"jobs"/run->name+".run").string());
// job after-run script
if(fs::exists(cfgDir/"jobs"/run->name+".after"))
run->addScript((cfgDir/"jobs"/run->name+".after").string());
run->addScript((cfgDir/"jobs"/run->name+".after").string(), true);
// per-node after-run script
if(fs::exists(cfgDir/"nodes"/node->name+".after"))
run->addScript((cfgDir/"nodes"/node->name+".after").string());
run->addScript((cfgDir/"nodes"/node->name+".after").string(), true);
// global after-run script
if(fs::exists(cfgDir/"after"))
run->addScript((cfgDir/"after").string());
run->addScript((cfgDir/"after").string(), true);
// add environment files
if(fs::exists(cfgDir/"env"))
@ -699,7 +699,7 @@ bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
// will be cancelled and the callback never called.
Run* r = run.get();
r->timeout = srv->addTimeout(timeout, [r](){
r->abort();
r->abort(true);
});
}
}

@ -128,17 +128,17 @@ bool Run::step() {
return false;
}
void Run::addScript(std::string scriptPath, std::string scriptWorkingDir) {
scripts.push({scriptPath, scriptWorkingDir});
void Run::addScript(std::string scriptPath, std::string scriptWorkingDir, bool runOnAbort) {
scripts.push({scriptPath, scriptWorkingDir, runOnAbort});
}
void Run::addEnv(std::string path) {
env.push_back(path);
}
void Run::abort() {
// clear all pending scripts
std::queue<Script>().swap(scripts);
void Run::abort(bool respectRunOnAbort) {
while(scripts.size() && (!respectRunOnAbort || !scripts.front().runOnAbort))
scripts.pop();
// if the Maybe is empty, wait() was already called on this process
KJ_IF_MAYBE(p, current_pid) {
kill(-*p, SIGTERM);

@ -56,16 +56,16 @@ public:
bool step();
// adds a script to the queue of scripts to be executed by this run
void addScript(std::string scriptPath, std::string scriptWorkingDir);
void addScript(std::string scriptPath, std::string scriptWorkingDir, bool runOnAbort = false);
// adds a script to the queue using the runDir as the scripts CWD
void addScript(std::string script) { addScript(script, runDir); }
void addScript(std::string script, bool runOnAbort = false) { addScript(script, runDir, runOnAbort); }
// adds an environment file that will be sourced before this run
void addEnv(std::string path);
// aborts this run
void abort();
void abort(bool respectRunOnAbort);
// called when a process owned by this run has been reaped. The status
// may be used to set the run's job status
@ -96,6 +96,7 @@ private:
struct Script {
std::string path;
std::string cwd;
bool runOnAbort;
};
std::queue<Script> scripts;

@ -105,7 +105,7 @@ TEST_F(RunTest, Abort) {
run.addScript("/usr/bin/yes");
run.step();
usleep(200); // TODO fix
run.abort();
run.abort(false);
wait();
EXPECT_EQ(RunState::ABORTED, run.result);
}
@ -116,7 +116,7 @@ TEST_F(RunTest, AbortAfterFailed) {
run.addScript("/usr/bin/yes");
run.step();
usleep(200); // TODO fix
run.abort();
run.abort(false);
wait();
EXPECT_EQ(RunState::FAILED, run.result);
}

Loading…
Cancel
Save