Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public virtual async Task<IOperationResult> HandleAsync(CancelWorkflowInstanceCo
var workflowInstanceReference = new ResourceReference<WorkflowInstance>(command.Name, command.Namespace);
var original = await resources.GetAsync<WorkflowInstance>(command.Name, command.Namespace, cancellationToken).ConfigureAwait(false)
?? throw new ProblemDetailsException(new(ProblemTypes.NotFound, ProblemTitles.NotFound, (int)HttpStatusCode.NotFound, ProblemDescriptions.ResourceNotFound.Format(workflowInstanceReference.ToString())));
if (!string.IsNullOrWhiteSpace(original.Status?.Phase) && original.Status?.Phase != WorkflowInstanceStatusPhase.Pending && original.Status?.Phase != WorkflowInstanceStatusPhase.Running && original.Status?.Phase != WorkflowInstanceStatusPhase.Waiting)
if (!string.IsNullOrWhiteSpace(original.Status?.Phase) && original.Status?.Phase != WorkflowInstanceStatusPhase.Pending && original.Status?.Phase != WorkflowInstanceStatusPhase.Running && original.Status?.Phase != WorkflowInstanceStatusPhase.Suspended && original.Status?.Phase != WorkflowInstanceStatusPhase.Waiting)
throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public virtual async Task<IOperationResult> HandleAsync(ResumeWorkflowInstanceCo
var workflowInstanceReference = new ResourceReference<WorkflowInstance>(command.Name, command.Namespace);
var original = await resources.GetAsync<WorkflowInstance>(command.Name, command.Namespace, cancellationToken).ConfigureAwait(false)
?? throw new ProblemDetailsException(new(ProblemTypes.NotFound, ProblemTitles.NotFound, (int)HttpStatusCode.NotFound, ProblemDescriptions.ResourceNotFound.Format(workflowInstanceReference.ToString())));
if (!string.IsNullOrWhiteSpace(original.Status?.Phase) && original.Status?.Phase != WorkflowInstanceStatusPhase.Waiting) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
if (!string.IsNullOrWhiteSpace(original.Status?.Phase) && original.Status?.Phase != WorkflowInstanceStatusPhase.Suspended) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
updated.Status.Phase = WorkflowInstanceStatusPhase.Running;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public virtual async Task<IOperationResult> HandleAsync(SuspendWorkflowInstanceC
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Running) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
updated.Status.Phase = WorkflowInstanceStatusPhase.Waiting;
updated.Status.Phase = WorkflowInstanceStatusPhase.Suspended;
var jsonPatch = JsonPatchUtility.CreateJsonPatchFromDiff(original, updated);
await resources.PatchStatusAsync<WorkflowInstance>(new(PatchType.JsonPatch, jsonPatch), command.Name, command.Namespace, cancellationToken: cancellationToken).ConfigureAwait(false);
return this.Ok();
Expand Down
21 changes: 20 additions & 1 deletion src/core/Synapse.Core/WorkflowInstanceStatusPhase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static class WorkflowInstanceStatusPhase
/// </summary>
public const string Running = "running";
/// <summary>
/// Indicates that the workflow's execution is waiting for user or event input
/// Indicates that the workflow's execution has been suspended
/// </summary>
public const string Suspended = "suspended";
/// <summary>
/// Indicates that the workflow's execution is waiting for event(s)
/// </summary>
public const string Waiting = "waiting";
/// <summary>
Expand All @@ -44,4 +48,19 @@ public static class WorkflowInstanceStatusPhase
/// </summary>
public const string Faulted = "faulted";

/// <summary>
/// Gets a new <see cref="IEnumerable{T}"/> containing all workflow instance status phases
/// </summary>
/// <returns>A new <see cref="IEnumerable{T}"/> containing all workflow instance status phases</returns>
public static IEnumerable<string> AsEnumerable()
{
yield return Pending;
yield return Running;
yield return Suspended;
yield return Waiting;
yield return Completed;
yield return Cancelled;
yield return Faulted;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected virtual async Task<ServiceAccount> GetServiceAccountAsync(Cancellation
/// <returns>A boolean indicating whether or not the handler should resume the execution of the handled workflow instance</returns>
protected virtual bool ShouldResumeExecution(string? statusPhase)
{
if (statusPhase == WorkflowInstanceStatusPhase.Waiting)
if (statusPhase == WorkflowInstanceStatusPhase.Suspended)
{
this._suspended = true;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/runner/Synapse.Runner/Services/RunnerApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected virtual async Task OnHandleStatusPhaseChangedAsync(string? phase, Canc
{
switch (phase)
{
case WorkflowInstanceStatusPhase.Waiting:
case WorkflowInstanceStatusPhase.Suspended:
await this.OnSuspendAsync(cancellationToken).ConfigureAwait(false);
break;
case WorkflowInstanceStatusPhase.Cancelled:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,11 +698,11 @@ public virtual async Task<TaskInstance> SkipAsync(TaskInstance task, object? res
/// <inheritdoc/>
public virtual async Task SuspendAsync(CancellationToken cancellationToken = default)
{
if (this.Instance.Status?.Phase == WorkflowInstanceStatusPhase.Waiting) return;
if (this.Instance.Status?.Phase == WorkflowInstanceStatusPhase.Suspended) return;
using var @lock = await this.Lock.LockAsync(cancellationToken).ConfigureAwait(false);
var originalInstance = this.Instance.Clone();
this.Instance.Status ??= new();
this.Instance.Status.Phase = WorkflowInstanceStatusPhase.Waiting;
this.Instance.Status.Phase = WorkflowInstanceStatusPhase.Suspended;
var run = this.Instance.Status.Runs?.LastOrDefault();
if (run != null) run.EndedAt = DateTimeOffset.Now;
var jsonPatch = JsonPatchUtility.CreateJsonPatchFromDiff(originalInstance, this.Instance);
Expand Down
2 changes: 1 addition & 1 deletion src/runner/Synapse.Runner/Services/WorkflowExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public virtual async Task ExecuteAsync(CancellationToken cancellationToken = def
await this.StartAsync(this.CancellationTokenSource.Token).ConfigureAwait(false);
break;
case WorkflowInstanceStatusPhase.Running:
case WorkflowInstanceStatusPhase.Waiting:
case WorkflowInstanceStatusPhase.Suspended:
await this.ResumeAsync(this.CancellationTokenSource.Token).ConfigureAwait(false);
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task SuspendAsync(string name, string @namespace, CancellationToken
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Running) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
updated.Status.Phase = WorkflowInstanceStatusPhase.Waiting;
updated.Status.Phase = WorkflowInstanceStatusPhase.Suspended;
var jsonPatch = JsonPatchUtility.CreateJsonPatchFromDiff(original, updated);
await this.Resources.PatchStatusAsync<WorkflowInstance>(new(PatchType.JsonPatch, jsonPatch), name, @namespace, cancellationToken: cancellationToken).ConfigureAwait(false);
}
Expand All @@ -49,7 +49,7 @@ public async Task ResumeAsync(string name, string @namespace, CancellationToken
var workflowInstanceReference = new ResourceReference<WorkflowInstance>(name, @namespace);
var original = await this.Resources.GetAsync<WorkflowInstance>(name, @namespace, cancellationToken).ConfigureAwait(false)
?? throw new ProblemDetailsException(new(ProblemTypes.NotFound, ProblemTitles.NotFound, (int)HttpStatusCode.NotFound, ProblemDescriptions.ResourceNotFound.Format(workflowInstanceReference.ToString())));
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Waiting) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Suspended) throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
updated.Status.Phase = WorkflowInstanceStatusPhase.Running;
Expand All @@ -64,7 +64,7 @@ public async Task CancelAsync(string name, string @namespace, CancellationToken
var workflowInstanceReference = new ResourceReference<WorkflowInstance>(name, @namespace);
var original = await this.Resources.GetAsync<WorkflowInstance>(name, @namespace, cancellationToken).ConfigureAwait(false)
?? throw new ProblemDetailsException(new(ProblemTypes.NotFound, ProblemTitles.NotFound, (int)HttpStatusCode.NotFound, ProblemDescriptions.ResourceNotFound.Format(workflowInstanceReference.ToString())));
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Pending && original.Status?.Phase != WorkflowInstanceStatusPhase.Running && original.Status?.Phase != WorkflowInstanceStatusPhase.Waiting)
if (original.Status?.Phase != WorkflowInstanceStatusPhase.Pending && original.Status?.Phase != WorkflowInstanceStatusPhase.Running && original.Status?.Phase != WorkflowInstanceStatusPhase.Suspended)
throw new ProblemDetailsException(new(ProblemTypes.AdmissionFailed, ProblemTitles.AdmissionFailed, (int)HttpStatusCode.BadRequest, $"The workflow instance '{workflowInstanceReference}' is in an expected phase '{original.Status?.Phase}'"));
var updated = original.Clone()!;
updated.Status ??= new();
Expand Down
Loading