Skip to content

Commit

Permalink
Small tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
sburmanoctopus committed Jan 20, 2025
1 parent 0702813 commit 9a00c66
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 70 deletions.
32 changes: 10 additions & 22 deletions source/Octopus.Tentacle.Client/AggregateScriptExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public AggregateScriptExecutor(ITentacleClientTaskLog logger,
ITentacleClientObserver tentacleClientObserver,
TentacleClientOptions clientOptions,
IHalibutRuntime halibutRuntime,
ServiceEndPoint serviceEndPoint, TimeSpan onCancellationAbandonCompleteScriptAfter) : this(logger, tentacleClientObserver, clientOptions, halibutRuntime, serviceEndPoint, null, onCancellationAbandonCompleteScriptAfter)
ServiceEndPoint serviceEndPoint,
TimeSpan onCancellationAbandonCompleteScriptAfter) : this(logger, tentacleClientObserver, clientOptions, halibutRuntime, serviceEndPoint, null, onCancellationAbandonCompleteScriptAfter)
{
}

Expand All @@ -56,11 +57,9 @@ internal AggregateScriptExecutor(ITentacleClientTaskLog logger,
{
var operationMetricsBuilder = ClientOperationMetricsBuilder.Start();

// Pick what service to use.
var scriptServiceToUse = await DetermineScriptServiceVersionToUse(cancellationToken, operationMetricsBuilder);


var scriptOrchestratorFactory = GetNewScriptOrchestratorFactory(operationMetricsBuilder);
var scriptOrchestratorFactory = CreateScriptOrchestratorFactory(operationMetricsBuilder);

var orchestrator = scriptOrchestratorFactory.CreateScriptExecutor(scriptServiceToUse);
return await orchestrator.StartScript(executeScriptCommand, startScriptIsBeingReAttempted, cancellationToken);
Expand All @@ -70,8 +69,8 @@ async Task<ScriptServiceVersion> DetermineScriptServiceVersionToUse(Cancellation
{
try
{
return await new ScriptServicePicker(clientsHolder.CapabilitiesServiceV2, logger, rpcCallExecutor, clientOptions, operationMetricsBuilder)
.DetermineScriptServiceVersionToUse(cancellationToken);
var scriptServicePicker = new ScriptServicePicker(clientsHolder.CapabilitiesServiceV2, logger, rpcCallExecutor, clientOptions, operationMetricsBuilder);
return await scriptServicePicker.DetermineScriptServiceVersionToUse(cancellationToken);
}
catch (Exception ex) when (cancellationToken.IsCancellationRequested)
{
Expand All @@ -83,7 +82,7 @@ async Task<ScriptServiceVersion> DetermineScriptServiceVersionToUse(Cancellation
{
var operationMetricsBuilder = ClientOperationMetricsBuilder.Start();

var scriptOrchestratorFactory = GetNewScriptOrchestratorFactory(operationMetricsBuilder);
var scriptOrchestratorFactory = CreateScriptOrchestratorFactory(operationMetricsBuilder);

var orchestrator = scriptOrchestratorFactory.CreateScriptExecutor(ticketForNextNextStatus.WhichService);

Expand All @@ -94,36 +93,25 @@ async Task<ScriptServiceVersion> DetermineScriptServiceVersionToUse(Cancellation
{
var operationMetricsBuilder = ClientOperationMetricsBuilder.Start();

var scriptOrchestratorFactory = GetNewScriptOrchestratorFactory(operationMetricsBuilder);
var scriptOrchestratorFactory = CreateScriptOrchestratorFactory(operationMetricsBuilder);

var orchestrator = scriptOrchestratorFactory.CreateScriptExecutor(ticketForNextNextStatus.WhichService);

return await orchestrator.CancelScript(ticketForNextNextStatus, cancellationToken);
}

public Task<ScriptStatus?> Finish(ICommandContext commandContext, CancellationToken scriptExecutionCancellationToken)
{
throw new NotImplementedException();
}

public Task<(ScriptStatus, ICommandContext)> CancelScript(ScriptTicket scriptTicket, CancellationToken cancellationToken)
{
var operationMetricsBuilder = ClientOperationMetricsBuilder.Start();
throw new System.NotImplementedException();
}


public async Task<ScriptStatus?> CleanUpScript(ICommandContext ticketForNextNextStatus, CancellationToken cancellationToken)
{
var operationMetricsBuilder = ClientOperationMetricsBuilder.Start();

var scriptOrchestratorFactory = GetNewScriptOrchestratorFactory(operationMetricsBuilder);
var scriptOrchestratorFactory = CreateScriptOrchestratorFactory(operationMetricsBuilder);

var orchestrator = scriptOrchestratorFactory.CreateScriptExecutor(ticketForNextNextStatus.WhichService);

return await orchestrator.CleanUpScript(ticketForNextNextStatus, cancellationToken);
}

ScriptOrchestratorFactory GetNewScriptOrchestratorFactory(ClientOperationMetricsBuilder operationMetricsBuilder)
ScriptOrchestratorFactory CreateScriptOrchestratorFactory(ClientOperationMetricsBuilder operationMetricsBuilder)
{
return new ScriptOrchestratorFactory(clientsHolder,
rpcCallExecutor,
Expand Down
19 changes: 2 additions & 17 deletions source/Octopus.Tentacle.Client/Scripts/IScriptExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,16 @@

namespace Octopus.Tentacle.Client.Scripts
{
public interface IScriptExecutor {
public interface IScriptExecutor
{
Task<(ScriptStatus, ICommandContext)> StartScript(ExecuteScriptCommand command,
StartScriptIsBeingReAttempted startScriptIsBeingReAttempted,
CancellationToken scriptExecutionCancellationToken);

/// <summary>
/// Returns a status or null when scriptExecutionCancellationToken is null.
/// </summary>
/// <param name="commandContext"></param>
/// <param name="scriptExecutionCancellationToken"></param>
/// <returns></returns>
Task<(ScriptStatus, ICommandContext)> GetStatus(ICommandContext commandContext, CancellationToken scriptExecutionCancellationToken);

Task<(ScriptStatus, ICommandContext)> CancelScript(ICommandContext commandContext, CancellationToken scriptExecutionCancellationToken);

/// <summary>
/// Use this cancel method if only the ScriptTicket is known, e.g. we called StartScript but never got a response.
/// Inheritors
/// </summary>
/// <param name="scriptTicket"></param>
/// <param name="hasStartScriptBeenCalledBefore"></param>
/// <returns></returns>
// Task<(ScriptStatus, ICommandContext)> CancelScript(ScriptTicket scriptTicket, CancellationToken cancellationToken);


Task<ScriptStatus?> CleanUpScript(ICommandContext commandContext, CancellationToken scriptExecutionCancellationToken);
}
}
12 changes: 0 additions & 12 deletions source/Octopus.Tentacle.Client/Scripts/IScriptOrchestrator.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

namespace Octopus.Tentacle.Client.Scripts
{
public sealed class ObservingScriptOrchestrator : IScriptOrchestrator
public sealed class ObservingScriptOrchestrator
{
readonly IScriptObserverBackoffStrategy scriptObserverBackOffStrategy;
readonly OnScriptStatusResponseReceived onScriptStatusResponseReceived;
readonly OnScriptCompleted onScriptCompleted;
readonly ITentacleClientTaskLog logger;

IScriptExecutor scriptExecutor;
readonly IScriptExecutor scriptExecutor;

public ObservingScriptOrchestrator(
IScriptObserverBackoffStrategy scriptObserverBackOffStrategy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace Octopus.Tentacle.Client.Scripts
{
// TODO: this is not an orchestrator factory.
class ScriptOrchestratorFactory
{
readonly RpcCallExecutor rpcCallExecutor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public class ScriptServicePicker
readonly TentacleClientOptions clientOptions;
readonly ClientOperationMetricsBuilder clientOperationMetricsBuilder;

internal ScriptServicePicker(IAsyncClientCapabilitiesServiceV2 clientCapabilitiesServiceV2, ITentacleClientTaskLog logger, RpcCallExecutor rpcCallExecutor, TentacleClientOptions clientOptions, ClientOperationMetricsBuilder clientOperationMetricsBuilder)
internal ScriptServicePicker(
IAsyncClientCapabilitiesServiceV2 clientCapabilitiesServiceV2,
ITentacleClientTaskLog logger,
RpcCallExecutor rpcCallExecutor,
TentacleClientOptions clientOptions,
ClientOperationMetricsBuilder clientOperationMetricsBuilder)
{
this.clientCapabilitiesServiceV2 = clientCapabilitiesServiceV2;
this.logger = logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,15 @@ StartScriptCommandV2 Map(ExecuteScriptCommand command)
return (MapToScriptStatus(r), MapToNextStatus(r));
}

private ScriptStatus MapToScriptStatus(ScriptStatusResponseV2 scriptStatusResponse)
ScriptStatus MapToScriptStatus(ScriptStatusResponseV2 scriptStatusResponse)
{
return new ScriptStatus(scriptStatusResponse.State, scriptStatusResponse.ExitCode, scriptStatusResponse.Logs);
}

private ICommandContext MapToNextStatus(ScriptStatusResponseV2 scriptStatusResponse)
ICommandContext MapToNextStatus(ScriptStatusResponseV2 scriptStatusResponse)
{
return new DefaultCommandContext(scriptStatusResponse.Ticket, scriptStatusResponse.NextLogSequence, ScriptServiceVersion.ScriptServiceVersion2);
}
public ProcessState GetState(ScriptStatusResponseV2 response) => response.State;

public async Task<(ScriptStatus, ICommandContext)> StartScript(ExecuteScriptCommand executeScriptCommand,
StartScriptIsBeingReAttempted startScriptIsBeingReAttempted,
Expand Down

0 comments on commit 9a00c66

Please sign in to comment.