Files
UnrealEngineUWP/Engine/Source/Programs/Horde/Horde.Server/Tasks/RestartTaskSource.cs
Ben Marsh 637187c618 Horde: Rename the Horde.Build project to Horde.Server.
#preflight none

[CL 24688228 by Ben Marsh in ue5-main branch]
2023-03-17 09:50:40 -04:00

55 lines
1.6 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using System.Threading;
using System.Threading.Tasks;
using Google.Protobuf;
using Google.Protobuf.WellKnownTypes;
using Horde.Server.Agents;
using Horde.Server.Agents.Leases;
using Horde.Server.Jobs;
using Horde.Server.Logs;
using Horde.Server.Utilities;
using HordeCommon;
using HordeCommon.Rpc.Tasks;
namespace Horde.Server.Tasks
{
class RestartTaskSource : TaskSourceBase<RestartTask>
{
public override string Type => "Restart";
public override TaskSourceFlags Flags => TaskSourceFlags.AllowWhenDisabled | TaskSourceFlags.AllowDuringDowntime;
readonly ILogFileService _logService;
public RestartTaskSource(ILogFileService logService)
{
_logService = logService;
OnLeaseStartedProperties.Add(nameof(RestartTask.LogId), x => LogId.Parse(x.LogId));
}
public override async Task<Task<AgentLease?>> AssignLeaseAsync(IAgent agent, CancellationToken cancellationToken)
{
if (!agent.RequestRestart)
{
return Skip(cancellationToken);
}
if (agent.Leases.Count > 0)
{
return await DrainAsync(cancellationToken);
}
LeaseId leaseId = LeaseId.GenerateNewId();
ILogFile log = await _logService.CreateLogFileAsync(JobId.Empty, leaseId, agent.SessionId, LogType.Json, useNewStorageBackend: false, cancellationToken: cancellationToken);
RestartTask task = new RestartTask();
task.LogId = log.Id.ToString();
byte[] payload = Any.Pack(task).ToByteArray();
return Lease(new AgentLease(leaseId, "Restart", null, null, log.Id, LeaseState.Pending, null, true, payload));
}
}
}