Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.

If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!

Differences between sdk classes RemoteExecuteOperation, ExecuteOperation and RemoteJob



  • Hello,
    i'm trying to understand what are the differences between these classes in the SDK.
    Looking at examples on github they seems similar, but Remote* classes seems to already be inside the remote machine, so .net code work directly on the server (maybe it's windows only?) while with non-Remote you need to get an agent service with code like

    var fileOps = context.Agent.TryGetService<ILinuxFileOperationsExecuter>()
    var ps = await context.Agent.GetServiceAsync<IRemoteProcessExecuter>().ConfigureAwait(false)
    

    I dont understand exactly the use of RemoteJob classes, what is the correct use for that


  • inedo-engineer

    Hi @flavio-campana_0936,

    An ExecuteOperation is the most simple Operation class available. You just implement the ExecuteAsync method, and that code by the execution engine when the Operation is invoked in your OtterScript. This (and all operations) have a ExecuteCommandLineAsync helper method, which is sent to the server in context.

    To interact with the server in context, you need to use the Agent property on the executionContext that's passed into the ExecuteAsync method. Because there are a lot of agent types and versions (Inedo Agent, Inedo Agent on Linux, PowerShell Agent, SSH Agent, Local Agent, etc.), you can use the TryGetService method to see if the agent supports what you want to do. Not all agents support all services. I think you've already seen how this works.

    One of the agent services available is IRemoteJobExecuter. This essentially just performs a long-running task on the remote server, via the agent. For this service to be supported, the agent must support .NET; I think all agents do at this point (even SSH) thanks to .NET core.

    A RemoteJob is the class used to describe what this long-running task is. It contains information about what you want to do, has its own ExecuteAsync method that will run on the server, and can stream log messages back to BuildMaster/Otter. When defining a RemoteJob, you need to serialize/deserialize everything on your own.

    For example, if your job simply wanted to add two numbers together, you'd need to Serialize the two numbers, then Deserialize them, then serialize a response, and deserialize the response. It's a bit complex.

    This is where the RemoteExecutionOperation comes in.

    It has a "lifecycle"of three methods:

    • BeforeRemoteExecuteAsync (optional, happens on BuildMaster/Otter server)
    • RemoteExecuteAsync (required, executes on remote server)
    • AfterRemoteExecuteAsync (optional, happens on BuildMaster/Otter server)

    Hope all this helps!


Log in to reply
 

Inedo Website HomeSupport HomeCode of ConductForums GuideDocumentation