diff --git a/src/Mindee/Http/MindeeApi.cs b/src/Mindee/Http/MindeeApi.cs
index 4ddf9f6e..2f1f5417 100644
--- a/src/Mindee/Http/MindeeApi.cs
+++ b/src/Mindee/Http/MindeeApi.cs
@@ -159,7 +159,10 @@ private static void AddWorkflowRequestParameters(WorkflowParameter workflowParam
if (workflowParameter.Priority != null)
{
- request.AddParameter(name: "priority", value: workflowParameter.Priority);
+ request.AddParameter(
+ name: "priority",
+ value: workflowParameter.Priority != null ?
+ workflowParameter.Priority.ToString()?.ToLower() : null);
}
}
diff --git a/src/Mindee/Http/WorkflowParameter.cs b/src/Mindee/Http/WorkflowParameter.cs
index 701a6052..5668efdb 100644
--- a/src/Mindee/Http/WorkflowParameter.cs
+++ b/src/Mindee/Http/WorkflowParameter.cs
@@ -1,3 +1,4 @@
+using System;
using Mindee.Input;
namespace Mindee.Http
@@ -16,7 +17,7 @@ public class WorkflowParameter : GenericParameter
///
/// Priority to give to the execution.
///
- public string Priority { get; }
+ public ExecutionPriority? Priority { get; }
///
/// Workflow parameters.
@@ -29,7 +30,7 @@ public class WorkflowParameter : GenericParameter
public WorkflowParameter(
LocalInputSource localSource,
UrlInputSource urlSource, bool fullText,
- string alias, string priority) : base(localSource, urlSource,
+ string alias, ExecutionPriority? priority) : base(localSource, urlSource,
fullText)
{
Alias = alias;
diff --git a/src/Mindee/Input/ExecutionPriority.cs b/src/Mindee/Input/ExecutionPriority.cs
new file mode 100644
index 00000000..a36d48a3
--- /dev/null
+++ b/src/Mindee/Input/ExecutionPriority.cs
@@ -0,0 +1,60 @@
+using System;
+using System.ComponentModel;
+using System.Runtime.Serialization;
+using System.Text.Json;
+using System.Text.Json.Serialization;
+
+namespace Mindee.Input
+{
+ ///
+ /// Priority for a workflow execution.
+ ///
+ public enum ExecutionPriority
+ {
+ ///
+ /// Low priority.
+ ///
+ [EnumMember(Value = "low")] Low,
+
+ ///
+ /// Medium priority.
+ ///
+ [EnumMember(Value = "medium")] Medium,
+
+ ///
+ /// Hight priority.
+ ///
+ [EnumMember(Value = "high")] High
+ }
+
+ ///
+ /// Deserializer for the ExecutionPriority enum.
+ ///
+ ///
+ public class StringEnumConverter : JsonConverter where T : struct, Enum
+ {
+ ///
+ /// Read a JSON value.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
+ {
+ string value = reader.GetString();
+ return Enum.TryParse(value, true, out var result) ? result : default;
+ }
+
+ ///
+ /// Retrieves a JSON value.
+ ///
+ ///
+ ///
+ ///
+ public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
+ {
+ writer.WriteStringValue(value.ToString().ToLower());
+ }
+ }
+}
diff --git a/src/Mindee/MindeeClient.cs b/src/Mindee/MindeeClient.cs
index 6cac60d2..3011eb52 100644
--- a/src/Mindee/MindeeClient.cs
+++ b/src/Mindee/MindeeClient.cs
@@ -623,7 +623,7 @@ public async Task> ExecuteWorkflowAsync(
WorkflowOptions workflowOptions = null,
PageOptions pageOptions = null)
{
- _logger?.LogInformation("Workflow enqueing {} ...", inputSource.Filename);
+ _logger?.LogInformation("Sending '{}' to workflow '{}'...", inputSource.Filename, workflowId);
if (pageOptions != null && inputSource.IsPdf())
{
@@ -631,10 +631,7 @@ public async Task> ExecuteWorkflowAsync(
new SplitQuery(inputSource.FileBytes, pageOptions)).File;
}
- if (workflowOptions == null)
- {
- workflowOptions = new WorkflowOptions();
- }
+ workflowOptions ??= new WorkflowOptions();
return await _mindeeApi.PostWorkflowExecution(
workflowId,
diff --git a/src/Mindee/MindeeClientOptions.cs b/src/Mindee/MindeeClientOptions.cs
index 6775c1d3..3379054d 100644
--- a/src/Mindee/MindeeClientOptions.cs
+++ b/src/Mindee/MindeeClientOptions.cs
@@ -1,5 +1,6 @@
using System;
using Mindee.Exceptions;
+using Mindee.Input;
namespace Mindee
{
@@ -118,7 +119,7 @@ public sealed class WorkflowOptions
///
/// Priority to give to the execution.
///
- public string Priority { get; }
+ public ExecutionPriority? Priority { get; }
///
@@ -133,7 +134,7 @@ public sealed class WorkflowOptions
///
///
///
- public WorkflowOptions(string alias = null, string priority = null, bool fullText = false)
+ public WorkflowOptions(string alias = null, ExecutionPriority? priority = null, bool fullText = false)
{
Alias = alias;
Priority = priority;
diff --git a/src/Mindee/Parsing/Common/Execution.cs b/src/Mindee/Parsing/Common/Execution.cs
index 24248124..f634ed5f 100644
--- a/src/Mindee/Parsing/Common/Execution.cs
+++ b/src/Mindee/Parsing/Common/Execution.cs
@@ -1,5 +1,6 @@
using System;
using System.Text.Json.Serialization;
+using Mindee.Input;
using Mindee.Product.Generated;
namespace Mindee.Parsing.Common
@@ -44,7 +45,8 @@ namespace Mindee.Parsing.Common
/// Priority of the execution.
///
[JsonPropertyName("priority")]
- public string Priority { get; set; }
+ [JsonConverter(typeof(StringEnumConverter))]
+ public ExecutionPriority Priority { get; set; }
///
/// The time at which the file was tagged as reviewed.
diff --git a/tests/Mindee.UnitTests/Workflow/WorklowTest.cs b/tests/Mindee.UnitTests/Workflow/WorklowTest.cs
index de8542bb..5e508b6a 100644
--- a/tests/Mindee.UnitTests/Workflow/WorklowTest.cs
+++ b/tests/Mindee.UnitTests/Workflow/WorklowTest.cs
@@ -77,7 +77,7 @@ public async Task SendingADocumentToAnExecutionShouldDeserializeResponseCorrectl
Assert.Equal("default_sample.jpg", response.Execution.File.Name);
Assert.Equal("8c75c035-e083-4e77-ba3b-7c3598bd1d8a", response.Execution.Id);
Assert.Null(response.Execution.Inference);
- Assert.Equal("medium", response.Execution.Priority);
+ Assert.Equal(ExecutionPriority.Medium, response.Execution.Priority);
Assert.Null(response.Execution.ReviewedAt);
Assert.Null(response.Execution.ReviewedPrediction);
Assert.Equal("processing", response.Execution.Status);
@@ -123,7 +123,7 @@ public async Task SendingADocumentToAnExecutionWithPriorityAndAliasShouldDeseria
Assert.Equal("default_sample.jpg", response.Execution.File.Name);
Assert.Equal("b743e123-e18c-4b62-8a07-811a4f72afd3", response.Execution.Id);
Assert.Null(response.Execution.Inference);
- Assert.Equal("low", response.Execution.Priority);
+ Assert.Equal(ExecutionPriority.Low, response.Execution.Priority);
Assert.Null(response.Execution.ReviewedAt);
Assert.Null(response.Execution.ReviewedPrediction);
Assert.Equal("processing", response.Execution.Status);