You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
55 lines
1.6 KiB
C#
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));
|
|
}
|
|
}
|
|
}
|