mirror of
https://github.com/ohwgiles/laminar.git
synced 2024-10-27 20:34:20 +00:00
resolves #52: timeout prevents .after script
Mark .after scripts as executing even after a timeout abort
This commit is contained in:
parent
a2d30ad2ea
commit
ab7be5a6c9
@ -587,7 +587,7 @@ void Laminar::notifyConfigChanged()
|
|||||||
|
|
||||||
void Laminar::abortAll() {
|
void Laminar::abortAll() {
|
||||||
for(std::shared_ptr<Run> run : activeJobs) {
|
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());
|
run->addScript((cfgDir/"jobs"/run->name+".run").string());
|
||||||
// job after-run script
|
// job after-run script
|
||||||
if(fs::exists(cfgDir/"jobs"/run->name+".after"))
|
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
|
// per-node after-run script
|
||||||
if(fs::exists(cfgDir/"nodes"/node->name+".after"))
|
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
|
// global after-run script
|
||||||
if(fs::exists(cfgDir/"after"))
|
if(fs::exists(cfgDir/"after"))
|
||||||
run->addScript((cfgDir/"after").string());
|
run->addScript((cfgDir/"after").string(), true);
|
||||||
|
|
||||||
// add environment files
|
// add environment files
|
||||||
if(fs::exists(cfgDir/"env"))
|
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.
|
// will be cancelled and the callback never called.
|
||||||
Run* r = run.get();
|
Run* r = run.get();
|
||||||
r->timeout = srv->addTimeout(timeout, [r](){
|
r->timeout = srv->addTimeout(timeout, [r](){
|
||||||
r->abort();
|
r->abort(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/run.cpp
10
src/run.cpp
@ -128,17 +128,17 @@ bool Run::step() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Run::addScript(std::string scriptPath, std::string scriptWorkingDir) {
|
void Run::addScript(std::string scriptPath, std::string scriptWorkingDir, bool runOnAbort) {
|
||||||
scripts.push({scriptPath, scriptWorkingDir});
|
scripts.push({scriptPath, scriptWorkingDir, runOnAbort});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Run::addEnv(std::string path) {
|
void Run::addEnv(std::string path) {
|
||||||
env.push_back(path);
|
env.push_back(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Run::abort() {
|
void Run::abort(bool respectRunOnAbort) {
|
||||||
// clear all pending scripts
|
while(scripts.size() && (!respectRunOnAbort || !scripts.front().runOnAbort))
|
||||||
std::queue<Script>().swap(scripts);
|
scripts.pop();
|
||||||
// if the Maybe is empty, wait() was already called on this process
|
// if the Maybe is empty, wait() was already called on this process
|
||||||
KJ_IF_MAYBE(p, current_pid) {
|
KJ_IF_MAYBE(p, current_pid) {
|
||||||
kill(-*p, SIGTERM);
|
kill(-*p, SIGTERM);
|
||||||
|
@ -56,16 +56,16 @@ public:
|
|||||||
bool step();
|
bool step();
|
||||||
|
|
||||||
// adds a script to the queue of scripts to be executed by this run
|
// 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
|
// 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
|
// adds an environment file that will be sourced before this run
|
||||||
void addEnv(std::string path);
|
void addEnv(std::string path);
|
||||||
|
|
||||||
// aborts this run
|
// aborts this run
|
||||||
void abort();
|
void abort(bool respectRunOnAbort);
|
||||||
|
|
||||||
// called when a process owned by this run has been reaped. The status
|
// called when a process owned by this run has been reaped. The status
|
||||||
// may be used to set the run's job status
|
// may be used to set the run's job status
|
||||||
@ -96,6 +96,7 @@ private:
|
|||||||
struct Script {
|
struct Script {
|
||||||
std::string path;
|
std::string path;
|
||||||
std::string cwd;
|
std::string cwd;
|
||||||
|
bool runOnAbort;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::queue<Script> scripts;
|
std::queue<Script> scripts;
|
||||||
|
@ -105,7 +105,7 @@ TEST_F(RunTest, Abort) {
|
|||||||
run.addScript("/usr/bin/yes");
|
run.addScript("/usr/bin/yes");
|
||||||
run.step();
|
run.step();
|
||||||
usleep(200); // TODO fix
|
usleep(200); // TODO fix
|
||||||
run.abort();
|
run.abort(false);
|
||||||
wait();
|
wait();
|
||||||
EXPECT_EQ(RunState::ABORTED, run.result);
|
EXPECT_EQ(RunState::ABORTED, run.result);
|
||||||
}
|
}
|
||||||
@ -116,7 +116,7 @@ TEST_F(RunTest, AbortAfterFailed) {
|
|||||||
run.addScript("/usr/bin/yes");
|
run.addScript("/usr/bin/yes");
|
||||||
run.step();
|
run.step();
|
||||||
usleep(200); // TODO fix
|
usleep(200); // TODO fix
|
||||||
run.abort();
|
run.abort(false);
|
||||||
wait();
|
wait();
|
||||||
EXPECT_EQ(RunState::FAILED, run.result);
|
EXPECT_EQ(RunState::FAILED, run.result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user