Skip to content

Commit

Permalink
Merge pull request #470 from serverlessworkflow/feat-stand-alone-runner
Browse files Browse the repository at this point in the history
Added a new stand-alone execution mode to the runner
  • Loading branch information
cdavernas authored Dec 16, 2024
2 parents f532e8a + 6d2baf0 commit c4181aa
Show file tree
Hide file tree
Showing 37 changed files with 1,250 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public interface IDocumentApiClient
/// <param name="id">The id of the <see cref="Document"/> to delete</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/></param>
/// <returns>The <see cref="Document"/> with the specified id</returns>
Task DeletesAsync(string id, CancellationToken cancellationToken = default);
Task DeleteAsync(string id, CancellationToken cancellationToken = default);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public virtual async Task UpdateAsync(string id, object content, CancellationTok
}

/// <inheritdoc/>
public virtual async Task DeletesAsync(string id, CancellationToken cancellationToken = default)
public virtual async Task DeleteAsync(string id, CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(id);
var uri = $"{PathPrefix}/{id}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Http/Synapse.Api.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Library</OutputType>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/api/Synapse.Api.Server/Synapse.Api.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/Synapse.Cli/Synapse.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Synapse.Core/Synapse.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
18 changes: 18 additions & 0 deletions src/core/Synapse.Core/SynapseDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,24 @@ public static class Runner
/// </summary>
public const string Name = Prefix + "NAME";

/// <summary>
/// Exposes constants about environment variables related to runner cloud events
/// </summary>
public static class CloudEvents
{

/// <summary>
/// Gets the prefix for all environment variables related to runner cloud events
/// </summary>
public const string Prefix = Runner.Prefix + "CLOUD_EVENTS_";

/// <summary>
/// Gets the environment variable used to configure the runner's cloud event sink
/// </summary>
public const string Sink = Prefix + "SINK";

}

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/operator/Synapse.Operator/Synapse.Operator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<NeutralLanguage>en</NeutralLanguage>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>alpha5.7</VersionSuffix>
<VersionSuffix>alpha5.8</VersionSuffix>
<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>
<FileVersion>$(VersionPrefix)</FileVersion>
<Authors>The Synapse Authors</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,19 @@ public class RunnerCloudEventOptions
public RunnerCloudEventOptions()
{
var env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.LifecycleEvents);
if(!string.IsNullOrWhiteSpace(env) && bool.TryParse(env, out var publishLifecycleEvents)) this.PublishLifecycleEvents = publishLifecycleEvents;
if (!string.IsNullOrWhiteSpace(env) && bool.TryParse(env, out var publishLifecycleEvents)) this.PublishLifecycleEvents = publishLifecycleEvents;
env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.CloudEvents.Sink);
if (!string.IsNullOrWhiteSpace(env) && Uri.TryCreate(env, UriKind.RelativeOrAbsolute, out var sink)) this.Sink = sink;
}

/// <summary>
/// Gets/sets a boolean indicating whether or not the Synapse Runner should produce lifecycle events. Defaults to `true`.
/// </summary>
public virtual bool PublishLifecycleEvents { get; set; } = true;

/// <summary>
/// Gets/sets the
/// </summary>
public virtual Uri? Sink { get; set; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class RunnerContainerOptions
public RunnerContainerOptions()
{
var env = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Runner.ContainerPlatform)?.ToLowerInvariant();
if (string.IsNullOrWhiteSpace(env)) throw new NullReferenceException("The runner's container platform must be configured");
if (string.IsNullOrWhiteSpace(env)) env = ContainerPlatform.Docker;
switch (env)
{
case ContainerPlatform.Docker:
Expand Down
35 changes: 35 additions & 0 deletions src/runner/Synapse.Runner/Configuration/RunnerExecutionMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.Serialization;

namespace Synapse.Runner.Configuration;

/// <summary>
/// Enumerates all modes of execution for the Synapse Runner application
/// </summary>
public enum RunnerExecutionMode
{
/// <summary>
/// The runner operates in a connected mode, interacting with the remote API.
/// In this mode, the runner depends on external services and APIs for its functionality.
/// </summary>
[EnumMember(Value = "connected")]
Connected,
/// <summary>
/// The runner operates in a standalone mode, functioning independently without relying on the remote API.
/// This mode is ideal for scenarios where external dependencies are unavailable or not required.
/// </summary>
[EnumMember(Value = "standalone")]
StandAlone
}
30 changes: 30 additions & 0 deletions src/runner/Synapse.Runner/Configuration/RunnerLoggingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2024-Present The Synapse Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.Serialization;

namespace Synapse.Runner.Configuration;

/// <summary>
/// Represents the options used to configure a Synapse Runner's logging
/// </summary>
[DataContract]
public class RunnerLoggingOptions
{

/// <summary>
/// Gets/sets the path to the file, if any, to output logs to
/// </summary>
public virtual string? OutputFilePath { get; set; }

}
10 changes: 10 additions & 0 deletions src/runner/Synapse.Runner/Configuration/RunnerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ namespace Synapse.Runner.Configuration;
public class RunnerOptions
{

/// <summary>
/// Gets/sets the runner's execution mode
/// </summary>
public RunnerExecutionMode ExecutionMode => string.IsNullOrWhiteSpace(this.Workflow.DefinitionFilePath) ? RunnerExecutionMode.Connected : RunnerExecutionMode.StandAlone;

/// <summary>
/// Gets/sets the options used to configure the Synapse API the runner must use
/// </summary>
Expand All @@ -43,6 +48,11 @@ public class RunnerOptions
/// </summary>
public virtual RunnerContainerOptions Containers { get; set; } = new();

/// <summary>
/// Gets/sets the options used to configure a Synapse Runner's logging
/// </summary>
public virtual RunnerLoggingOptions Logging { get; set; } = new();

/// <summary>
/// Gets the options used to configure the secrets of the Synapse Runner
/// </summary>
Expand Down
40 changes: 34 additions & 6 deletions src/runner/Synapse.Runner/Configuration/WorkflowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,52 @@ public class WorkflowOptions
/// </summary>
public WorkflowOptions()
{
this.Instance = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Workflow.Instance)!;
this.InstanceQualifiedName = Environment.GetEnvironmentVariable(SynapseDefaults.EnvironmentVariables.Workflow.Instance)!;
}

/// <summary>
/// Gets/sets the qualified name of the workflow instance to run
/// Gets/sets the qualified name of the workflow instance to run. Required if the execution mode has been set to <see cref="RunnerExecutionMode.Connected"/>, otherwise ignored
/// </summary>
public virtual string Instance { get; set; }
public virtual string? InstanceQualifiedName { get; set; }

/// <summary>
/// Gets/sets the name of the definition's file, if any. Required if the execution mode has been set to <see cref="RunnerExecutionMode.StandAlone"/>, otherwise ignored
/// </summary>
public virtual string? DefinitionFilePath { get; set; }

/// <summary>
/// Gets/sets the name of the file, if any, that defines the input of to the workflow to run. Ignored if the execution mode has been set to <see cref="RunnerExecutionMode.Connected"/>
/// </summary>
public virtual string? InputFilePath { get; set; }

/// <summary>
/// Gets/sets the name of the file, if any, to write the workflow's output to. Ignored if the execution mode has been set to <see cref="RunnerExecutionMode.Connected"/>
/// </summary>
public virtual string? OutputFilePath { get; set; }

/// <summary>
/// Gets/sets the workflow's output format. Ignored if execution mode has been set to <see cref="RunnerExecutionMode.Connected"/>
/// </summary>
public virtual WorkflowOutputFormat OutputFormat { get; set; }

/// <summary>
/// Gets the namespace of the workflow instance to run
/// </summary>
/// <returns>The namespace of the workflow instance to run</returns>
public virtual string GetInstanceNamespace() => this.Instance.Split('.', StringSplitOptions.RemoveEmptyEntries).Last();
public virtual string GetInstanceNamespace()
{
if (string.IsNullOrWhiteSpace(this.InstanceQualifiedName)) throw new NullReferenceException("The instance qualified name is null or empty");
return this.InstanceQualifiedName.Split('.', StringSplitOptions.RemoveEmptyEntries).Last();
}

/// <summary>
/// Gets the name of the workflow instance to run
/// </summary>
/// <returns>The name of the workflow instance to run</returns>
public virtual string GetInstanceName() => this.Instance.Split('.', StringSplitOptions.RemoveEmptyEntries).First();
public virtual string GetInstanceName()
{
if (string.IsNullOrWhiteSpace(this.InstanceQualifiedName)) throw new NullReferenceException("The instance qualified name is null or empty");
return this.InstanceQualifiedName.Split('.', StringSplitOptions.RemoveEmptyEntries).First();
}

}
}
Loading

0 comments on commit c4181aa

Please sign in to comment.