Skip to content

Commit 23a86cd

Browse files
committed
OrcLib: CommandAgent: handle configuration attribute 'timeout'
1 parent 844d685 commit 23a86cd

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/OrcLib/CommandAgent.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,11 @@ std::shared_ptr<CommandExecute> CommandAgent::PrepareCommandExecute(const std::s
697697
break;
698698
}
699699

700+
if (message->GetTimeout().has_value())
701+
{
702+
retval->m_timeout = *message->GetTimeout();
703+
}
704+
700705
if (m_bChildDebug)
701706
{
702707
Log::Debug(L"CommandAgent: Configured dump file path '{}'", m_TempDir);
@@ -780,6 +785,17 @@ HRESULT CommandAgent::ExecuteNextCommand()
780785

781786
if (SUCCEEDED(hr))
782787
{
788+
if (command->GetTimeout().has_value() && command->GetTimeout()->count() != 0)
789+
{
790+
auto timer = std::make_shared<Concurrency::timer<CommandMessage::Message>>(
791+
(unsigned int)command->GetTimeout()->count(),
792+
CommandMessage::MakeAbortMessage(command->GetProcessHandle()),
793+
static_cast<CommandMessage::ITarget*>(&m_cmdAgentBuffer));
794+
795+
command->SetTimeoutTimer(timer);
796+
timer->start();
797+
}
798+
783799
{
784800
Concurrency::critical_section::scoped_lock s(m_cs);
785801
m_RunningCommands.push_back(command);
@@ -1271,6 +1287,15 @@ void CommandAgent::run()
12711287
}
12721288
}
12731289
break;
1290+
case CommandMessage::Abort: {
1291+
Log::Info("Abort process");
1292+
1293+
if (!TerminateProcess(request->ProcessHandle(), E_ABORT))
1294+
{
1295+
Log::Error(L"Failed to terminate process [{}]", LastWin32Error());
1296+
}
1297+
}
1298+
break;
12741299
case CommandMessage::TerminateAll: {
12751300
Log::Critical(L"Kill all running tasks: {}", m_Keyword);
12761301

src/OrcLib/CommandAgent.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ class CommandAgent : public Concurrency::agent
7777
{
7878
public:
7979
CommandAgent(
80-
CommandMessage::ISource& source,
80+
CommandMessage::PriorityMessageBuffer& source,
8181
ArchiveMessage::ITarget& archive,
8282
CommandNotification::ITarget& target,
8383
unsigned int max_running_tasks = DEFAULT_MAX_RUNNING_PROCESSES)
84-
: m_source(source)
84+
: m_cmdAgentBuffer(source)
85+
, m_source(source)
8586
, m_target(target)
8687
, m_archive(archive)
8788
, m_MaximumRunningSemaphore(max_running_tasks)
@@ -133,6 +134,7 @@ class CommandAgent : public Concurrency::agent
133134

134135
CommandNotification::ITarget& m_target;
135136
CommandMessage::ISource& m_source;
137+
CommandMessage::PriorityMessageBuffer& m_cmdAgentBuffer;
136138

137139
ArchiveMessage::ITarget& m_archive;
138140

src/OrcLib/CommandExecute.h

+6
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ class CommandExecute
212212
const std::optional<std::wstring>& GetOrcTool() const { return m_orcTool; }
213213
void SetOrcTool(const std::optional<std::wstring>& tool) { m_orcTool = tool; }
214214

215+
const std::optional<std::chrono::milliseconds>& GetTimeout() const { return m_timeout; }
216+
217+
void SetTimeoutTimer(std::shared_ptr<void> timer) { m_timeoutTimer = std::move(timer); }
218+
215219
~CommandExecute(void);
216220

217221
private:
@@ -220,6 +224,8 @@ class CommandExecute
220224
std::wstring m_commandLine;
221225
STARTUPINFO m_si;
222226
PROCESS_INFORMATION m_pi;
227+
std::optional<std::chrono::milliseconds> m_timeout;
228+
std::shared_ptr<void> m_timeoutTimer;
223229
std::optional<std::wstring> m_originResourceName;
224230
std::optional<std::wstring> m_originFriendlyName;
225231
std::optional<std::wstring> m_executableSha1;

0 commit comments

Comments
 (0)