добивание живых задач, отключение лишней рассылки админам, настройка удаления или не удаления пакета на машине
This commit is contained in:
2025-03-14 13:48:30 +03:00
parent 9f4eb9d88e
commit a2017f9e01
17 changed files with 95 additions and 32 deletions

View File

@@ -24,6 +24,21 @@ public:
ptr = NULL;
}
}
String read() {
int c;
String res;
do {
c = fgetc(ptr);
switch (c){
case EOF:
break;
default:
res.addChar(c);
break;
}
} while (c!=EOF);
return res;
}
Text* readLines() {
Text* lines = new Text();
int c;

View File

@@ -236,7 +236,11 @@ public:
// прошло больше 10 секунд, проверяем нужно ли завершиться
if (Utils::getAbsoluteTime() - timer_killed > 10) {
if (checkKilled()) {
ToLog("killed");
ToLog("killing active tasks...");
ToLog("activeTasks="+ String((int)activeTasks)+";busyKernels="+String((int)busyKernels));
killActiveTasks(activeTaskSet);
ToLog("done");
ToLog("waiting for active tasks...");
while (busyKernels) {
ToLog("activeTasks="+ String((int)activeTasks)+";busyKernels="+String((int)busyKernels));
checkTasksFinish(activeTaskSet, toDel, activeTasks, done, busyKernels, buf);
@@ -246,7 +250,7 @@ public:
toDel.clear();
Utils::Sleep(5);
}
ToLog("exit for main while");
ToLog("exit of main while");
killed = true;
break;
}
@@ -262,7 +266,7 @@ public:
File tmp(outFile, String(buf.c_str()));
}
else {
//всегда финальное состояние.
//всегда финальное состояние. даже если это компиляция.
saveState("RunningEnd");
ToLog("quit application");
std::exit(0);
@@ -289,6 +293,11 @@ public:
bool checkKilled() const {
return Utils::Exists("kill");
}
void killActiveTasks(const set<T*>& activeTaskSet) {
for (auto& task : activeTaskSet){
task->kill();
}
}
void checkTasksFinish(const set<T*>& activeTaskSet, vector<T*>& toDel, size_t& activeTasks,
size_t& done, int& busyKernels, string& buf) {
// проверяем нет ли завершившихся задач
@@ -299,10 +308,7 @@ public:
activeTasks--;
done += task->getKernels();
busyKernels -= task->getKernels();
printf(" done task with %d kernels and id %ld\n", task->getKernels(), task->getId());
buf += to_string(task->getId()) + " " + string(task->printState().getCharArray()) + " " + to_string(task->getTotalTime()) + "\n";
//copy after end of while
//task->copyResults(pathRes);
}
}
}

View File

@@ -202,4 +202,19 @@ public:
Utils::Copy(workspace + "/err.txt", resultPath + "/err.txt");
return resultPath;
}
void kill(){
//--
String("killing task "+id).println();
String pid_path(workspace+"/PID");
if (Utils::Exists(pid_path)){
File pid_file(&pid_path);
String pid = pid_file.read();
if (!pid.isEmpty()){
String kill_command = "kill -2 "+ pid;
kill_command.println();
system(kill_command.getCharArray());
}
}
//--
}
};

View File

@@ -28,6 +28,11 @@ int main(int argc, char ** argv){
int pid = fork();
if (pid == 0)
execvp( argv[1],args);
else {
FILE * pid_file = fopen("PID","w");
fprintf(pid_file,"%d", pid);
fclose(pid_file);
}
return 0;
}
catch (const char * exception){

View File

@@ -1 +1 @@
21
24