Skip to content

Commit

Permalink
feat: CleanUpInProgressCommands moved inside the CommandsProcessingTask
Browse files Browse the repository at this point in the history
With this change the function can be private.
  • Loading branch information
sdvendramini committed Dec 6, 2024
1 parent 081d214 commit e4165a4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
17 changes: 9 additions & 8 deletions src/agent/command_handler/include/command_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace command_handler
const auto executor = co_await boost::asio::this_coro::executor;
std::unique_ptr<boost::asio::steady_timer> expTimer = std::make_unique<boost::asio::steady_timer>(executor);

CleanUpInProgressCommands(ReportCommandResult);

while (m_keepRunning.load())
{
auto cmd = GetCommandFromQueue();
Expand Down Expand Up @@ -85,8 +87,12 @@ namespace command_handler
}
}

void CleanUpInProgressCommands(
std::function<void(const std::optional<std::vector<module_command::CommandEntry>>&)> callback)
/// @brief Stops the command handler
void Stop();

private:
template<typename T>
void CleanUpInProgressCommands(std::function<void(T&)> ReportCommandResult)
{
auto cmds = m_commandStore.GetCommandByStatus(module_command::Status::IN_PROGRESS);

Expand All @@ -97,16 +103,11 @@ namespace command_handler
cmd.ExecutionResult.ErrorCode = module_command::Status::FAILURE;
cmd.ExecutionResult.Message = "Agent stopped during execution";
m_commandStore.UpdateCommand(cmd);
ReportCommandResult(cmd);
}
}

callback(cmds);
}

/// @brief Stops the command handler
void Stop();

private:
/// @brief Indicates whether the command handler is running or not
std::atomic<bool> m_keepRunning = true;

Expand Down
12 changes: 0 additions & 12 deletions src/agent/src/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,6 @@ Agent::Agent(const std::string& configFilePath, std::unique_ptr<ISignalHandler>

m_taskManager.Start(
m_configurationParser->GetConfig<size_t>("agent", "thread_count").value_or(config::DEFAULT_THREAD_COUNT));

m_commandHandler.CleanUpInProgressCommands(
[this](const auto& inProgressCommands)
{
if (inProgressCommands != std::nullopt)
{
for (auto& cmd : *inProgressCommands)
{
ReportCommandResult(cmd, m_messageQueue);
}
}
});
}

Agent::~Agent()
Expand Down

0 comments on commit e4165a4

Please sign in to comment.