// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "localrunner.h" #if ZEN_WITH_COMPUTE_SERVICES # include # include namespace asio { class io_context; } namespace zen::compute { /** Cross-platform process runner backed by SubprocessManager. Subclasses LocalProcessRunner, reusing sandbox management, worker manifesting, input/output handling, and shared action preparation. Replaces the polling-based monitor thread with async exit callbacks driven by SubprocessManager, and delegates CPU/memory metrics sampling to the manager's built-in round-robin sampler. A ProcessGroup (backed by a JobObject on Windows, process group on POSIX) is used for bulk cancellation on shutdown. This runner does not perform any platform-specific sandboxing (AppContainer, namespaces, Seatbelt). It is intended as a simpler, cross-platform alternative to the platform-specific runners for non-sandboxed workloads. */ class ManagedProcessRunner : public LocalProcessRunner { public: ManagedProcessRunner(ChunkResolver& Resolver, const std::filesystem::path& BaseDir, DeferredDirectoryDeleter& Deleter, WorkerThreadPool& WorkerPool, int32_t MaxConcurrentActions = 0); ~ManagedProcessRunner(); void Shutdown() override; [[nodiscard]] SubmitResult SubmitAction(Ref Action) override; void CancelRunningActions() override; bool CancelAction(int ActionLsn) override; [[nodiscard]] bool IsHealthy() override { return true; } private: static constexpr int kIoThreadCount = 4; // Exit callback posted on an io_context thread. void OnProcessExit(int ActionLsn, int ExitCode); std::unique_ptr m_IoContext; std::unique_ptr m_SubprocessManager; ProcessGroup* m_ProcessGroup = nullptr; std::vector m_IoThreads; }; } // namespace zen::compute #endif