// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using EpicGames.UBA.Impl;
namespace EpicGames.UBA
{
///
/// Type of execution used for process
///
public enum ProcessExecutionType
{
///
/// Process executed locally without detouring
///
Native,
///
/// Process executed locally with detouring enabled
///
Local,
///
/// Process executed on a remote session
///
Remote,
///
/// Process was never executed and instead downloaded from cache
///
Cache,
///
/// Process was skipped and never executed
///
Skip,
}
///
///
public interface IProcessFinishedInfo
{
///
/// Type of execution
///
ProcessExecutionType ExecutionType { get; }
///
/// Process exit code
///
int ExitCode { get; }
///
/// Captured output lines
///
List LogLines { get; }
///
/// The remote host that ran the process, if run remotely
///
string? ExecutingHost { get; }
///
/// Total time spent for the processor
///
TimeSpan TotalProcessorTime { get; }
///
/// Total wall time spent
///
TimeSpan TotalWallTime { get; }
///
/// Peak memory used, requires a job object so will only be non-zero for Windows hosts.
///
long PeakMemoryUsed { get; }
///
/// UserData that was provided in EnqueueProcess
///
object UserData { get; }
///
/// Native uba handle to process.
///
nint ProcessHandle { get; }
}
///
///
public enum ProcessFinishedResponse
{
///
/// None means that nothing should be done
///
None,
///
/// RerunLocal means that we want to re-run the process locally with detouring enabled
///
RerunLocal,
///
/// RerunNative means that we want to re-run the process locally without detouring
///
RerunNative,
}
///
/// Base interface for uba config file
///
public interface IScheduler : IBaseInterface
{
///
/// Start the scheduler. It will start processing enqueued processes straight away
///
void Start();
///
/// Queue process.
///
uint EnqueueProcess(ProcessStartInfo info, double weight, bool canDetour, bool canExecuteRemotely, int[]? dependencies, byte[]? knownInputs, uint knownInputsCount, uint cacheBucket, uint memoryGroup, ulong predictedMemoryUsage, object userData);
///
/// Cancel all active processes and skip queued ones
///
void Cancel();
///
/// Returns true if no processes are running or queued
///
bool IsEmpty { get; }
///
/// Accumulated weight of all processes that are Queued and can run right now (dependencies are done)
///
double GetProcessWeightThatCanRunRemotelyNow();
///
/// Set callback for when process has finished
///
void SetProcessFinishedCallback(Func processFinished);
///
/// Allows uba to disable remote execution if running out of processes that can execute remotely
///
void SetAllowDisableRemoteExecution();
///
/// Create a scheduler
///
/// Session
/// List of cache clients
/// Max number of local processes scheduler can run in parallel
/// Force all processes that can to run remote
public static IScheduler CreateScheduler(ISessionServer session, IEnumerable cacheClients, int maxLocalProcessors, bool forceRemote)
{
return new SchedulerImpl(session, cacheClients, maxLocalProcessors, forceRemote);
}
}
}