Skip to content

Commit 2642268

Browse files
authored
Merge pull request #549 from serverlessworkflow/fix-workflow-instance-status-update
Fixed the `WorkflowInstanceHandler` to ignore 304 errors when updating workflow instance status
2 parents 4f4a314 + 8144042 commit 2642268

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

src/core/Synapse.Core/Resources/RuntimeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public record RuntimeDefinition
4242
/// Gets the runtime mode
4343
/// </summary>
4444
[IgnoreDataMember, JsonIgnore, YamlIgnore]
45-
public virtual string Mode => this.Native != null ? OperatorRuntimeMode.Native : this.Docker != null ? OperatorRuntimeMode.Docker : this.Kubernetes != null ? OperatorRuntimeMode.Kubernetes : throw new Exception("The runtime mode must be set");
45+
public virtual string Mode => this.Kubernetes != null ? OperatorRuntimeMode.Kubernetes : this.Native != null ? OperatorRuntimeMode.Native : this.Docker != null ? OperatorRuntimeMode.Docker : throw new Exception("The runtime mode must be set");
4646

4747
}

src/operator/Synapse.Operator/Services/WorkflowInstanceHandler.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,23 +219,16 @@ protected virtual async Task OnPersistLogBatchAsync()
219219
protected virtual async Task UpdateWorkflowInstanceStatusAsync(Action<WorkflowInstanceStatus> statusUpdate, CancellationToken cancellationToken)
220220
{
221221
ArgumentNullException.ThrowIfNull(statusUpdate);
222-
var maxRetries = 3;
223-
for (var attempt = 0; attempt < maxRetries; attempt++)
222+
try
224223
{
225-
try
226-
{
227-
var original = this.WorkflowInstance.Resource;
228-
var updated = original.Clone()!;
229-
updated.Status ??= new();
230-
statusUpdate(updated.Status);
231-
var patch = JsonPatchUtility.CreateJsonPatchFromDiff(original, updated);
232-
await this.Resources.PatchStatusAsync<WorkflowInstance>(new Patch(PatchType.JsonPatch, patch), updated.GetName(), updated.GetNamespace(), null, false, cancellationToken).ConfigureAwait(false);
233-
}
234-
catch (ConcurrencyException) when (attempt + 1 < maxRetries)
235-
{
236-
await Task.Delay(TimeSpan.FromMilliseconds(100 * (attempt + 1)), cancellationToken).ConfigureAwait(false);
237-
}
224+
var original = this.WorkflowInstance.Resource;
225+
var updated = original.Clone()!;
226+
updated.Status ??= new();
227+
statusUpdate(updated.Status);
228+
var patch = JsonPatchUtility.CreateJsonPatchFromDiff(original, updated);
229+
await this.Resources.PatchStatusAsync<WorkflowInstance>(new Patch(PatchType.JsonPatch, patch), updated.GetName(), updated.GetNamespace(), null, false, cancellationToken).ConfigureAwait(false);
238230
}
231+
catch (ProblemDetailsException ex) when (ex.Problem.Status == (int)HttpStatusCode.NotModified) { }
239232
}
240233

241234
/// <summary>

src/operator/Synapse.Operator/appsettings.Development.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
"Uri": "http://localhost:5257"
1616
},
1717
"Runtime": {
18-
"Native": {
19-
"Directory": "..\\..\\..\\..\\..\\runner\\Synapse.Runner\\bin\\Debug\\net9.0\\",
20-
"Executable": "Synapse.Runner.exe"
18+
//"Native": {
19+
// "Directory": "..\\..\\..\\..\\..\\runner\\Synapse.Runner\\bin\\Debug\\net9.0\\",
20+
// "Executable": "Synapse.Runner.exe"
21+
//}
22+
"Kubernetes": {
23+
"Namespace": "default"
2124
}
2225
}
2326
}

src/runtime/Synapse.Runtime.Kubernetes/Services/KubernetesRuntime.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ public class KubernetesRuntime(IServiceProvider serviceProvider, ILoggerFactory
6868
protected virtual async Task InitializeAsync(CancellationToken cancellationToken = default)
6969
{
7070
if (this.Runner.Runtime.Kubernetes == null) throw new NullReferenceException($"Failed to initialize the Kubernetes Runtime because the operator is not configured to use Kubernetes as a runtime");
71-
var kubeconfig = string.IsNullOrWhiteSpace(this.Runner.Runtime.Kubernetes.Kubeconfig)
72-
? KubernetesClientConfiguration.InClusterConfig()
73-
: await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(this.Runner.Runtime.Kubernetes.Kubeconfig)).ConfigureAwait(false);
74-
this.Kubernetes = new k8s.Kubernetes(kubeconfig);
71+
var configuration = Environment.RunsInKubernetes()
72+
? KubernetesClientConfiguration.InClusterConfig()
73+
: (string.IsNullOrWhiteSpace(this.Runner.Runtime.Kubernetes.Kubeconfig)
74+
? KubernetesClientConfiguration.BuildDefaultConfig()
75+
: await KubernetesClientConfiguration.BuildConfigFromConfigFileAsync(new FileInfo(this.Runner.Runtime.Kubernetes.Kubeconfig)).ConfigureAwait(false));
76+
this.Kubernetes = new k8s.Kubernetes(configuration);
7577
}
7678

7779
/// <inheritdoc/>

0 commit comments

Comments
 (0)