// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; namespace EpicGames.Horde.Compute { /// /// Interface for uploading compute work to remote machines /// public interface IComputeClient { /// /// Find the most suitable cluster to execute a given compute assignment request /// /// Requirements for the agent /// Optional ID identifying the request over multiple calls, such as retrying the same request /// Optional preference of connection details /// Logger for output from this worker /// Cancellation token for the operation public Task GetClusterAsync(Requirements? requirements, string? requestId, ConnectionMetadataRequest? connection, ILogger logger, CancellationToken cancellationToken = default); /// /// Adds a new remote request /// /// Optional cluster ID. If not set, cluster will automatically be resolved by server /// Requirements for the agent /// Optional ID identifying the request over multiple calls, such as retrying the same request /// Optional preference of connection details /// Logger for output from this worker /// Cancellation token for the operation public Task TryAssignWorkerAsync(ClusterId? clusterId, Requirements? requirements, string? requestId, ConnectionMetadataRequest? connection, ILogger logger, CancellationToken cancellationToken = default); /// /// Declare resource needs for current client /// Helps inform the server about current demand. /// Can be called as often as necessary to keep needs up-to-date. /// /// Cluster to execute the request /// Which pool this applies to /// Properties with a target amount of each, such as CPU or RAM /// Cancellation token for the operation public Task DeclareResourceNeedsAsync(ClusterId clusterId, string pool, Dictionary resourceNeeds, CancellationToken cancellationToken = default); } /// /// Extension methods for /// public static class ComputeClientExtensions { /// public static Task TryAssignWorkerAsync(this IComputeClient computeClient, ClusterId clusterId, Requirements? requirements, string? requestId, ConnectionMode? connectionPreference, ILogger logger, CancellationToken cancellationToken = default) { ConnectionMetadataRequest cmr = new() { ModePreference = connectionPreference }; return computeClient.TryAssignWorkerAsync(clusterId, requirements, requestId, cmr, logger, cancellationToken); } /// [Obsolete("Prefer taking a requestId parameter")] public static Task TryAssignWorkerAsync(this IComputeClient computeClient, ClusterId clusterId, Requirements? requirements, ILogger logger, CancellationToken cancellationToken) { return computeClient.TryAssignWorkerAsync(clusterId, requirements, null, logger, cancellationToken); } /// [Obsolete("Prefer taking a connection parameter")] public static Task TryAssignWorkerAsync(this IComputeClient computeClient, ClusterId clusterId, Requirements? requirements, string? requestId, ILogger logger, CancellationToken cancellationToken = default) { return computeClient.TryAssignWorkerAsync(clusterId, requirements, requestId, null, logger, cancellationToken); } } /// /// Exception from ComputeClient /// public class ComputeClientException : Exception { /// public ComputeClientException(string? message) : base(message) { } } }