Skip to content

Commit d6ac40d

Browse files
Putting ScriptExecutor functionality into TentacleClient (#1060)
Putting ScriptExecutor functionality into TentacleClient
1 parent 1b68570 commit d6ac40d

File tree

6 files changed

+102
-27
lines changed

6 files changed

+102
-27
lines changed

source/Octopus.Tentacle.Client/ITentacleClient.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using Halibut;
55
using Halibut.Diagnostics;
6+
using Octopus.Tentacle.Client.EventDriven;
67
using Octopus.Tentacle.Client.Scripts;
78
using Octopus.Tentacle.Client.Scripts.Models;
89
using Octopus.Tentacle.Contracts;
@@ -16,7 +17,7 @@ public interface ITentacleClient : IDisposable
1617
Task<DataStream?> DownloadFile(string remotePath, ITentacleClientTaskLog logger, CancellationToken cancellationToken);
1718

1819
/// <summary>
19-
/// Execute a script on Tentacle
20+
/// Execute a script on Tentacle in its entirety.
2021
/// </summary>
2122
/// <param name="executeScriptCommand">The execute script command</param>
2223
/// <param name="onScriptStatusResponseReceived"></param>
@@ -31,5 +32,39 @@ Task<ScriptExecutionResult> ExecuteScript(
3132
OnScriptCompleted onScriptCompleted,
3233
ITentacleClientTaskLog logger,
3334
CancellationToken scriptExecutionCancellationToken);
35+
36+
/// <summary>
37+
/// Start the script.
38+
/// </summary>
39+
/// <returns>The result, which includes the CommandContext for the next command</returns>
40+
Task<ScriptOperationExecutionResult> StartScript(ExecuteScriptCommand command,
41+
StartScriptIsBeingReAttempted startScriptIsBeingReAttempted,
42+
ITentacleClientTaskLog logger,
43+
CancellationToken scriptExecutionCancellationToken);
44+
45+
/// <summary>
46+
/// Get the status.
47+
/// </summary>
48+
/// <param name="commandContext">The CommandContext from the previous command</param>
49+
/// <param name="logger"></param>
50+
/// <param name="scriptExecutionCancellationToken"></param>
51+
/// <returns>The result, which includes the CommandContext for the next command</returns>
52+
Task<ScriptOperationExecutionResult> GetStatus(CommandContext commandContext, ITentacleClientTaskLog logger, CancellationToken scriptExecutionCancellationToken);
53+
54+
/// <summary>
55+
/// Cancel the script.
56+
/// </summary>
57+
/// <param name="commandContext">The CommandContext from the previous command</param>
58+
/// <param name="logger"></param>
59+
/// <returns>The result, which includes the CommandContext for the next command</returns>
60+
Task<ScriptOperationExecutionResult> CancelScript(CommandContext commandContext, ITentacleClientTaskLog logger);
61+
62+
/// <summary>
63+
/// Complete the script.
64+
/// </summary>
65+
/// <param name="commandContext">The CommandContext from the previous command</param>
66+
/// <param name="logger"></param>
67+
/// <param name="scriptExecutionCancellationToken"></param>
68+
Task<ScriptStatus?> CompleteScript(CommandContext commandContext, ITentacleClientTaskLog logger, CancellationToken scriptExecutionCancellationToken);
3469
}
3570
}

source/Octopus.Tentacle.Client/ScriptExecutor.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Octopus.Tentacle.Client
1616
/// <summary>
1717
/// Executes scripts, on the best available script service.
1818
/// </summary>
19-
public class ScriptExecutor : IScriptExecutor
19+
class ScriptExecutor : IScriptExecutor
2020
{
2121
readonly ITentacleClientTaskLog logger;
2222
readonly ClientOperationMetricsBuilder operationMetricsBuilder;
@@ -25,22 +25,6 @@ public class ScriptExecutor : IScriptExecutor
2525
readonly RpcCallExecutor rpcCallExecutor;
2626
readonly TimeSpan onCancellationAbandonCompleteScriptAfter;
2727

28-
public ScriptExecutor(AllClients allClients,
29-
ITentacleClientTaskLog logger,
30-
ITentacleClientObserver tentacleClientObserver,
31-
TentacleClientOptions clientOptions,
32-
TimeSpan onCancellationAbandonCompleteScriptAfter)
33-
: this(
34-
allClients,
35-
logger,
36-
tentacleClientObserver,
37-
// For now, we do not support operation based metrics when used outside the TentacleClient. So just plug in a builder to discard.
38-
ClientOperationMetricsBuilder.Start(),
39-
clientOptions,
40-
onCancellationAbandonCompleteScriptAfter)
41-
{
42-
}
43-
4428
internal ScriptExecutor(AllClients allClients,
4529
ITentacleClientTaskLog logger,
4630
ITentacleClientObserver tentacleClientObserver,

source/Octopus.Tentacle.Client/Scripts/IScriptExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace Octopus.Tentacle.Client.Scripts
99
{
10-
public interface IScriptExecutor
10+
interface IScriptExecutor
1111
{
1212
/// <summary>
1313
/// Start the script.

source/Octopus.Tentacle.Client/Scripts/ObservingScriptOrchestrator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Octopus.Tentacle.Client.Scripts
88
{
9-
public sealed class ObservingScriptOrchestrator
9+
sealed class ObservingScriptOrchestrator
1010
{
1111
readonly IScriptObserverBackoffStrategy scriptObserverBackOffStrategy;
1212
readonly OnScriptStatusResponseReceived onScriptStatusResponseReceived;

source/Octopus.Tentacle.Client/ServiceHelpers/AllClients.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,14 @@
77

88
namespace Octopus.Tentacle.Client.ServiceHelpers
99
{
10-
public class AllClients
10+
class AllClients
1111
{
1212
public IAsyncClientScriptService ScriptServiceV1 { get; }
1313
public IAsyncClientScriptServiceV2 ScriptServiceV2 { get; }
1414
public IAsyncClientKubernetesScriptServiceV1 KubernetesScriptServiceV1 { get; }
1515
public IAsyncClientFileTransferService ClientFileTransferServiceV1 { get; }
1616
public IAsyncClientCapabilitiesServiceV2 CapabilitiesServiceV2 { get; }
17-
18-
public AllClients(IHalibutRuntime halibutRuntime, ServiceEndPoint serviceEndPoint) : this(halibutRuntime, serviceEndPoint, null)
19-
{
20-
}
21-
22-
17+
2318
internal AllClients(IHalibutRuntime halibutRuntime, ServiceEndPoint serviceEndPoint, ITentacleServiceDecoratorFactory? tentacleServicesDecoratorFactory)
2419
{
2520
ScriptServiceV1 = halibutRuntime.CreateAsyncClient<IScriptService, IAsyncClientScriptService>(serviceEndPoint);

source/Octopus.Tentacle.Client/TentacleClient.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Halibut;
66
using Halibut.ServiceModel;
7+
using Octopus.Tentacle.Client.EventDriven;
78
using Octopus.Tentacle.Client.Execution;
89
using Octopus.Tentacle.Client.Observability;
910
using Octopus.Tentacle.Client.Scripts;
@@ -187,6 +188,66 @@ public async Task<ScriptExecutionResult> ExecuteScript(ExecuteScriptCommand exec
187188
}
188189
}
189190

191+
public async Task<ScriptOperationExecutionResult> StartScript(
192+
ExecuteScriptCommand command,
193+
StartScriptIsBeingReAttempted startScriptIsBeingReAttempted,
194+
ITentacleClientTaskLog logger,
195+
CancellationToken scriptExecutionCancellationToken)
196+
{
197+
var scriptExecutor = new ScriptExecutor(
198+
allClients,
199+
logger,
200+
tentacleClientObserver,
201+
// For now, we do not support metrics for event-based operations.
202+
ClientOperationMetricsBuilder.Start(),
203+
clientOptions,
204+
OnCancellationAbandonCompleteScriptAfter);
205+
206+
return await scriptExecutor.StartScript(command, startScriptIsBeingReAttempted, scriptExecutionCancellationToken);
207+
}
208+
209+
public async Task<ScriptOperationExecutionResult> GetStatus(CommandContext commandContext, ITentacleClientTaskLog logger, CancellationToken scriptExecutionCancellationToken)
210+
{
211+
var scriptExecutor = new ScriptExecutor(
212+
allClients,
213+
logger,
214+
tentacleClientObserver,
215+
// For now, we do not support metrics for event-based operations.
216+
ClientOperationMetricsBuilder.Start(),
217+
clientOptions,
218+
OnCancellationAbandonCompleteScriptAfter);
219+
220+
return await scriptExecutor.GetStatus(commandContext, scriptExecutionCancellationToken);
221+
}
222+
223+
public async Task<ScriptOperationExecutionResult> CancelScript(CommandContext commandContext, ITentacleClientTaskLog logger)
224+
{
225+
var scriptExecutor = new ScriptExecutor(
226+
allClients,
227+
logger,
228+
tentacleClientObserver,
229+
// For now, we do not support metrics for event-based operations.
230+
ClientOperationMetricsBuilder.Start(),
231+
clientOptions,
232+
OnCancellationAbandonCompleteScriptAfter);
233+
234+
return await scriptExecutor.CancelScript(commandContext);
235+
}
236+
237+
public async Task<ScriptStatus?> CompleteScript(CommandContext commandContext, ITentacleClientTaskLog logger, CancellationToken scriptExecutionCancellationToken)
238+
{
239+
var scriptExecutor = new ScriptExecutor(
240+
allClients,
241+
logger,
242+
tentacleClientObserver,
243+
// For now, we do not support metrics for event-based operations.
244+
ClientOperationMetricsBuilder.Start(),
245+
clientOptions,
246+
OnCancellationAbandonCompleteScriptAfter);
247+
248+
return await scriptExecutor.CompleteScript(commandContext, scriptExecutionCancellationToken);
249+
}
250+
190251
public void Dispose()
191252
{
192253
}

0 commit comments

Comments
 (0)