This commit is contained in:
2023-12-03 19:01:25 +03:00
parent 878123d76f
commit 4318d6756f
2 changed files with 75 additions and 66 deletions

View File

@@ -112,7 +112,6 @@ public:
case Execution: case Execution:
if (task->getState() == WorkspaceReady) { if (task->getState() == WorkspaceReady) {
activeCount++; activeCount++;
task->start_time = Utils::getAbsoluteTime();
task->Start(); task->Start();
} }
else if (task->getState() == Running) { else if (task->getState() == Running) {

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include <chrono>
#include "File.h" #include "File.h"
#include "Utils.h" #include "Utils.h"
#include "Global.h" #include "Global.h"
@@ -41,56 +43,59 @@ protected:
int kernels; //получение зависит от типа задачи. int kernels; //получение зависит от типа задачи.
String workspace; String workspace;
TaskState state; TaskState state;
std::chrono::system_clock::time_point start_time;
public: public:
long long start_time; String printState() {
String printState(){ switch (state) {
switch(state){ case Inactive:
case Inactive: return String("Inactive");
return String("Inactive"); case Waiting:
case Waiting: return String("Waiting");
return String("Waiting"); case WorkspaceCreated:
case WorkspaceCreated: return String("WorkspaceCreated");
return String("WorkspaceCreated"); case WorkspaceReady:
case WorkspaceReady: return String("WorkspaceReady");
return String("WorkspaceReady"); case Running:
case Running: return String("Running");
return String("Running"); case Canceled:
case Canceled: return String("Canceled");
return String("Canceled"); case Finished:
case Finished: return String("Finished");
return String("Finished"); case FinishedAbortedByTimeout:
case FinishedAbortedByTimeout: return String("FinishedAbortedByTimeout");
return String("FinishedAbortedByTimeout"); case FinishedAbortedByUser:
case FinishedAbortedByUser: return String("FinishedAbortedByUser");
return String("FinishedAbortedByUser"); case Done:
case Done: return String("Done");
return String("Done"); case DoneWithErrors:
case DoneWithErrors: return String("DoneWithErrors");
return String("DoneWithErrors"); case AbortedByTimeout:
case AbortedByTimeout: return String("AbortedByTimeout");
return String("AbortedByTimeout"); case AbortedByUser:
case AbortedByUser: return String("AbortedByUser");
return String("AbortedByUser"); case Crushed:
case Crushed: return String("Crushed");
return String("Crushed"); case WrongTestFormat:
case WrongTestFormat: return String("WrongTestFormat");
return String("WrongTestFormat"); case InternalError:
case InternalError: return String("InternalError");
return String("InternalError"); case Queued:
case Queued: return String("Queued");
return String("Queued"); case NoSuchTask:
case NoSuchTask: return String("NoSuchTask");
return String("NoSuchTask"); case FailedToQueue:
case FailedToQueue: return String("FailedToQueue");
return String("FailedToQueue"); case AbortingByUser:
case AbortingByUser: return String("AbortingByUser");
return String("AbortingByUser"); default:
default: return "?";
return "?";
} }
} }
//-------------->> //-------------->>
void setStart() { start_time = std::chrono::system_clock::now(); }
long getId() { return id; } long getId() { return id; }
long setId(String* id_s) { long setId(String* id_s) {
return id = strtol(id_s->getCharArray(), NULL, 10); return id = strtol(id_s->getCharArray(), NULL, 10);
@@ -129,9 +134,9 @@ public:
int getKernels() const { return kernels; } int getKernels() const { return kernels; }
virtual void Start(bool dontCheck = false) { void Start(bool dontCheck = false) {
if (kernels <= freeKernels || dontCheck) { if (kernels <= freeKernels || dontCheck) {
setStart();
system(getStartCommand().getCharArray()); system(getStartCommand().getCharArray());
state = Running; state = Running;
//- //-
@@ -149,17 +154,22 @@ public:
if (Utils::Exists(workspace + "/TIMEOUT")) { if (Utils::Exists(workspace + "/TIMEOUT")) {
state = AbortedByTimeout; state = AbortedByTimeout;
//todo определить по интервалу времени на всякий случай. //todo определить по интервалу времени на всякий случай.
}else if (Utils::Exists(workspace+"/INTERRUPT")){ }
state=AbortedByUser; else if (Utils::Exists(workspace + "/INTERRUPT")) {
} else { state = AbortedByUser;
long long now = Utils::getAbsoluteTime(); }
long long delta = now-start_time; else {
if (maxtime<delta){ auto end_time = std::chrono::system_clock::now();
state=AbortedByTimeout; std::chrono::duration<double> diff_time = end_time - start_time;
}
if (maxtime * 1.1 < diff_time.count()) {
printf("SET STATUS ABORTED by timer to %ld with time %f sec / %f sec", id, diff_time.count(), maxtime * 1.1);
state = AbortedByTimeout;
}
} }
} }
if (state!=Running){
if (state != Running) {
//- //-
busyKernels = Utils::min(busyKernels - kernels, maxKernels); busyKernels = Utils::min(busyKernels - kernels, maxKernels);
freeKernels = Utils::max(0, maxKernels - busyKernels); freeKernels = Utils::max(0, maxKernels - busyKernels);