4 #include <Poco/SharedPtr.h>
5 #include <Poco/Timestamp.h>
6 #include <Poco/Logger.h>
7 #include <Poco/Thread.h>
8 #include <Poco/TaskManager.h>
30 : inherited(taskName_, nodeOptions_, message_, taskRequestSetExecute_, asyncTasksQueue_, resourceMonitor_, inputJsonMessage_, parentTaskId_)
41 std::time_t timeStart = now.epochTime();
54 for (
size_t i=0;i<subtasks.size();++i)
67 asyncTask.state = DRCETaskRequest::TaskState::IN_PROGRESS;
72 resultDataItem =
execute(applyPidHandler);
76 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName,
"DRCETaskShellHost::runTask before executeSubtasks()", Poco::Message::Priority::PRIO_TRACE));
95 std::stringstream outMsg;
96 outMsg <<
"DRCETaskShellHost::runTask isCancelled = " << std::boolalpha << isCancelled();
97 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName, outMsg.str(), Poco::Message::Priority::PRIO_TRACE));
101 asyncTask.state = DRCETaskRequest::TaskState::FINISHED;
106 outMsg <<
">>>>> FINISHED (" << taskId <<
")";
107 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName, outMsg.str(), Poco::Message::Priority::PRIO_TRACE));
111 asyncTask.state = DRCETaskRequest::TaskState::TERMINATED;
115 outMsg <<
">>>>> TERMINATED (" << taskId <<
")\n";
116 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName, outMsg.str(), Poco::Message::Priority::PRIO_TRACE));
119 if (statusFile.exists())
122 unsigned int errorCodeMainTask =
NO_ERROR;
132 taskState = DRCETaskRequest::TaskState::TERMINATED_BY_TTL;
143 DRCETaskRequest::RequestType::rtSetTaskExecute, taskState,
144 errorCode, errorMessage, asyncTask.pid, asyncTask.timeElapsed);
146 resultDataItem.
setTime(asyncTask.timeElapsed);
159 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName, outMsg.str(), Poco::Message::Priority::PRIO_TRACE));
164 for (std::map<unsigned int, bool>::iterator iter=sub.begin();iter!=sub.end();++iter)
167 outMsg <<
"DRCETaskShellHost::runTask cleanup() taskId: " << (*iter).first <<
" cleanup: " << std::boolalpha << (*iter).second;
168 Poco::Logger::root().log(Poco::Message(
drce_const::moduleName, outMsg.str(), Poco::Message::Priority::PRIO_TRACE));
174 catch(Poco::Exception& e)
178 asyncTask.state = DRCETaskRequest::TaskState::CRASHED;
184 catch(std::exception& e)
188 asyncTask.state = DRCETaskRequest::TaskState::CRASHED;
195 if (asyncTask.state != DRCETaskRequest::TaskState::TERMINATED)
206 Poco::Timestamp tsStart;
207 makeFilesBefore(taskRequestSetExecute);
210 Poco::SharedPtr<CommandResultData> pCommandResultData =
nullptr;
211 if (!taskRequestSetExecute.getCommandLine().empty())
214 taskRequestSetExecute.getSessionOptions().homeDir,
215 taskRequestSetExecute.getInputStream(),
216 taskRequestSetExecute.getSessionOptions().environments,
217 taskRequestSetExecute.getSessionOptions().shellName);
220 pCommandResultData = commandExecutor.
execute(
command, fn, taskRequestSetExecute.getSessionOptions().timeMax);
222 if (pCommandResultData.isNull())
225 resultDataItem.
setStdoutStream(pCommandResultData->getOutStream().str());
226 resultDataItem.
setStderrStream(pCommandResultData->getErrStream().str());
227 resultDataItem.
setExitStatus(pCommandResultData->getExitStatus());
228 resultDataItem.
setPid(pCommandResultData->getProcessId());
230 if (commandExecutor.getStatusExecution()==StarterExecutor::StatusExecution::seTerminated)
232 resultDataItem.
setState(static_cast<unsigned int>(DRCETaskRequest::TaskState::TERMINATED));
238 resultDataItem.
setState(static_cast<unsigned int>(DRCETaskRequest::TaskState::FINISHED));
241 resultDataItem.
setState(static_cast<unsigned int>(DRCETaskRequest::TaskState::FINISHED));
243 resultDataItem.
setRequestId(taskRequestSetExecute.getTaskId());
244 resultDataItem.
setRequestType(DRCETaskRequest::RequestType::rtSetTaskExecute);
245 resultDataItem.
setNodeName(nodeOptions.getNodeName());
246 resultDataItem.
setNodeHost(nodeOptions.getNodeHost());
247 resultDataItem.
setNodePort(nodeOptions.getNodePort());
249 makeFilesAfter(taskRequestSetExecute, resultDataItem);
251 if (!pCommandResultData.isNull())
253 if (pCommandResultData->getIsError())
259 resultDataItem.
setTime(getElapsedTimeMsec(tsStart));
261 return resultDataItem;