Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event driven script orchestrator #1058

Merged
merged 36 commits into from
Jan 21, 2025

Conversation

sburmanoctopus
Copy link
Contributor

@sburmanoctopus sburmanoctopus commented Jan 21, 2025

[sc-101635]

Background

Currently we only allow calling into tentacle client to run a script via the TentacleClient.ExecuteScript method. Although extremely simple it is not re-entrant. When we talk about re-entrancy we are considering the case the client gets turned off and on and wants to continue on. The deficiencies are:

  • when using SSv1 could start a script a second time
  • it will re-fetch all logs, rather than where or close to the point we left off from.
  • it doesn't work well from an event driven orchestrator.

Results

This PR was a continuation of the spike started here

In summary the changes are:

  • The ObservingOrchestrator is no longer abstract and becomes a thing that "just" knows how to run the life cycle of the script.
  • A new IScriptExecutor interface is created which allows driving script life cycle
    • This is now used by the ObservingOrchestrator
    • Could be used by an event driven orchestrator.
  • The ScriptService Orchestrators which inherited from ObservingOrchestrator, now implement IScriptExecutor. They now focus on implementing the main stages of script execution following a single interface.
    • They are also responsible from converting from types the client of the client might use to the types that go over the wire.
    • They are responsible for their own "quirks" providing a straight forward interface to interact with.
  • A ScriptExecutor is created which:
    • On start script determines which of the other ScriptServices to use.
    • On the other methods uses the given CommandContext to determine which script service to use.
    • In doing so it can deal with calling the correct service.
  • The ObservingOrchestrator is given a ScriptExecutor
    • Which is called by TentacleClient.ExecuteScript
    • In this way the existing tests are able to exercise the ScriptExecutor which is what an event driven orchestrator would call.
    • This reduces what an event driven orchestrator needs to implement to just what is done in ObservingOrchestrator

@sburmanoctopus sburmanoctopus marked this pull request as ready for review January 21, 2025 02:00
@sburmanoctopus sburmanoctopus requested a review from a team as a code owner January 21, 2025 02:00

namespace Octopus.Tentacle.Client.EventDriven
{
public class CommandContext
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider documenting what this class is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Done

{
public interface IScriptExecutor
{
Task<ScriptOperationExecutionResult> StartScript(ExecuteScriptCommand command,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to document that the resulting CommandContext should be used for the next call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

StartScriptIsBeingReAttempted startScriptIsBeingReAttempted,
CancellationToken scriptExecutionCancellationToken);

Task<ScriptOperationExecutionResult> GetStatus(CommandContext commandContext, CancellationToken scriptExecutionCancellationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think I actually preferred the tuple because the responses where not something that are really coupled AND I think it improved readability. ie it was clear each method was returning a CommandContext which might be enough to hint to the user to use that CommandContext for the next call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think I actually preferred the tuple because the responses where not something that are really coupled
🤔 I feel that the fact we return both implies that they are related.

I think it improved readability. ie it was clear each method was returning a CommandContext which might be enough to hint to the user to use that CommandContext for the next call.

🤔 I would have thought the property named ContextForNextCommand would be good enough. Plus, adding the documentation from the previous comment should be more than enough.

I personally don't like tuples at all, and feel this is much easier to understand. For now, let's leave it the way it is, and if we find it unhelpful we can address it then.

@@ -1,6 +1,7 @@
namespace Octopus.Tentacle.Client.Scripts
{
record ScriptServiceVersion(string Value)
// TODO should not be public.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we will address this in a future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be addressed as part of the work to use a serialized version of command context.

But yes, we shouldn't be leaving these TODOs.


namespace Octopus.Tentacle.Client.Scripts
{
public class UnsafeStartAttemptException : Exception
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is used we should document what it is about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -183,6 +183,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002EMemberReordering_002EMigrations_002ECSharpFileLayoutPatternRemoveIsAttributeUpgrade/@EntryIndexedValue">True</s:Boolean>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just dotnet things

@sburmanoctopus sburmanoctopus merged commit 67b07ca into main Jan 21, 2025
51 of 52 checks passed
@sburmanoctopus sburmanoctopus deleted the sast/event-driven-script-orchestrator branch January 21, 2025 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants