Skip to content

Commit

Permalink
Add support for updating a workflow execution (#55)
Browse files Browse the repository at this point in the history
* Add support for updating a workflow execution

* upping the sdk version in the github tests

* correct typo;

* downgrade the test version

* update changelog and version

* update broken link

* remove deprecated arguments

* fix tests

* omit fileserver test

* final fixes to make it run on github

* can we use the nunit3-console directly?

* trying to get back to old test setup

* fix

* try using dotnet

* Change path of asset image

* remove contentType from CreateDocument

* ignore the document-tests and try to include the tests for the delete endpoints

* Update tests

* status can no longer be updated

* remove deprecated argument

* Update changelog and github action version

* Fix local tests

* Uniform ignore messages

* Use an older version of prism
  • Loading branch information
magnurud authored Dec 19, 2023
1 parent cb923a5 commit c760b73
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 89 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core SDK ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v1.7.2
uses: actions/setup-dotnet@v4.0.0
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: Setup Prism
run: make prism-start
- name: Restore Tests
run: dotnet restore Test
- name: Run Tests
run: make test
run: dotnet test Test/Test.csproj

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## Version 5.0.0 - 2023-12-19

- Added status UpdateWorkflowExecution
- Remove width and height from CreateModel
- Remove width and height from UpdateModel
- Remove status from UpdateModel
- Remove contentType from CreateDocument

## Version 4.1.0 - 2023-06-27

- Added support for uploading document to file server

## Version 3.1.0 - 2022-03-28

- Added postprocessConfig to CreatePrediction
Expand Down
48 changes: 15 additions & 33 deletions Lucidtech/Las/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ public object DeleteAsset(string assetId) {
/// Creates a document handle, calls the POST /documents endpoint
/// </summary>
/// <param name="content"> Content to POST </param>
/// <param name="contentType"> A mime type for the document handle </param>
/// <param name="consentId"> An identifier to mark the owner of the document handle </param>
/// <param name="datasetId"> Specifies the dataset to which the document will be associated with </param>
/// <param name="groundTruth"> A list of items {label: value},
Expand All @@ -265,7 +264,6 @@ public object DeleteAsset(string assetId) {
/// </returns>
public object CreateDocument(
byte[] content,
string contentType,
string? consentId = null,
List<Dictionary<string, string>>? groundTruth = null,
string? datasetId = null
Expand Down Expand Up @@ -299,7 +297,7 @@ public object CreateDocument(

return response;
}

/// <summary>
/// Get documents from the REST API, calls the GET /documents endpoint.
/// </summary>
Expand Down Expand Up @@ -686,26 +684,20 @@ public object ListLogs(
}

/// <summary>Creates a model, calls the POST /models endpoint.</summary>
/// <param name="width">The number of pixels to be used for the input image width of your model</param>
/// <param name="height">The number of pixels to be used for the input image height of your model</param>
/// <param name="fieldConfig">Specification of the fields that the model is going to predict</param>
/// <param name="preprocessConfig">Specification of the processing steps prior to the prediction of an image</param>
/// <param name="name">Name of the model</param>
/// <param name="description">Description of the model</param>
/// <param name="attributes">Additional attributes</param>
/// <returns>Model response from REST API</returns>
public object CreateModel(
int width,
int height,
Dictionary<string, object> fieldConfig,
Dictionary<string, object>? preprocessConfig = null,
string? name = null,
string? description = null,
Dictionary<string, string?>? attributes = null
) {
var body = new Dictionary<string, object?> {
{"width", width},
{"height", height},
{"fieldConfig", fieldConfig}
};

Expand Down Expand Up @@ -769,36 +761,22 @@ public object GetModel(string modelId) {

/// <summary>Updates a model, calls the PATCH /models/{modelId} endpoint.</summary>
/// <param name="modelId">Id of the model</param>
/// <param name="width">The number of pixels to be used for the input image width of your model</param>
/// <param name="height">The number of pixels to be used for the input image height of your model</param>
/// <param name="fieldConfig">Specification of the fields that the model is going to predict</param>
/// <param name="preprocessConfig">Specification of the processing steps prior to the prediction of an image</param>
/// <param name="name">Name of the model</param>
/// <param name="description">Description of the model</param>
/// <param name="status">New status for the model</param>
/// <param name="attributes">Additional attributes</param>
/// <returns>Model response from REST API</returns>
public object UpdateModel(
string modelId,
int? width = null,
int? height = null,
Dictionary<string, object>? fieldConfig = null,
Dictionary<string, object>? preprocessConfig = null,
string? name = null,
string? description = null,
string? status = null,
Dictionary<string, string?>? attributes = null
) {
var body = new Dictionary<string, object?>();

if (width != null) {
body.Add("width", width);
}

if (height != null) {
body.Add("height", height);
}

if (fieldConfig != null) {
body.Add("fieldConfig", fieldConfig);
}
Expand All @@ -815,10 +793,6 @@ public object UpdateModel(
body.Add("description", description);
}

if (status != null) {
body.Add("status", status);
}

if (attributes != null) {
foreach (KeyValuePair<string, string?> entry in attributes) {
body.Add(entry.Key, entry.Value);
Expand Down Expand Up @@ -1710,23 +1684,31 @@ public object GetWorkflowExecution(string workflowId, string executionId) {
}

/// <summary>
/// Retry or end the processing of a workflow execution,
/// Change the processing of a workflow execution. Retry, end or mark as completed.
/// calls the PATCH /workflows/{workflowId}/executions/{executionId} endpoint.
/// </summary>
/// <example>
/// <code>
/// var response = client.UpdateWorkflowExecution("&lt;workflow_id&gt;", "&lt;execution_id&gt;", "&lt;next_transition_id&gt;");
/// var response = client.UpdateWorkflowExecution("&lt;workflow_id&gt;", "&lt;execution_id&gt;", nextTransitionId: "&lt;next_transition_id&gt;");
/// </code>
/// </example>
/// <param name="workflowId">Id of the workflow</param>
/// <param name="executionId">Id of the execution</param>
/// <param name="nextTransitionId">The next transition to transition into, to end the workflow-execution,
/// use: las:transition:commons-failed</param>
/// <param name="status">Update the execution with this status, can only update from succeeded to completed and vice versa.
/// <returns>WorkflowExecution response from REST API</returns>
public object UpdateWorkflowExecution(string workflowId, string executionId, string nextTransitionId) {
var body = new Dictionary<string, string> {
{"nextTransitionId", nextTransitionId}
};
public object UpdateWorkflowExecution(string workflowId, string executionId, string? nextTransitionId = null, string? status = null) {

Check warning on line 1701 in Lucidtech/Las/Client.cs

View workflow job for this annotation

GitHub Actions / publish-nuget

XML comment has badly formed XML -- 'Expected an end tag for element 'param'.'
var body = new Dictionary<string, string> {};

if (nextTransitionId != null) {
body.Add("nextTransitionId", nextTransitionId);
}

if (status != null) {
body.Add("status", status);
}

var request = ClientRestRequest(Method.PATCH, $"/workflows/{workflowId}/executions/{executionId}", body);
return ExecuteRequestResilient(this, request);
}
Expand Down
2 changes: 1 addition & 1 deletion Lucidtech/Lucidtech.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<TargetFrameworks>netstandard20</TargetFrameworks>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>Lucidtech.Las</PackageId>
<PackageVersion>4.1.0</PackageVersion>
<PackageVersion>5.0.0</PackageVersion>
<Title>Lucidtech AI Services</Title>
<Authors>Lucidtech AS</Authors>
<Description>SDK for accessing Lucidtech AI Services</Description>
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ build-test: restore-test
msbuild Test/Test.csproj

test: build-test
mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./Test/bin/Debug/net461/Test.dll
mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./Test/bin/Debug/net47/Test.dll
mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./Test/bin/Debug/net472/Test.dll
cd Test && mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./bin/Debug/net461/Test.dll
cd Test && mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./bin/Debug/net47/Test.dll
cd Test && mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./bin/Debug/net472/Test.dll

single-test: build-test
if [ -z "$(name)" ]; then echo 'you need to specify the name of your test ex. name=TestDeleteBatch' && exit 1; fi
mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./Test/bin/Debug/net472/Test.dll --test=Test.TestClient.$(name)
cd Test && mono $(HOME)/.nuget/packages/nunit.consolerunner/3.11.1/tools/nunit3-console.exe --stoponerror ./bin/Debug/net472/Test.dll --test=Test.TestClient.$(name)

prism-start:
@echo "Starting mock API..."
docker run -t \
--init \
--detach \
-p 4010:4010 \
stoplight/prism:4.5.0 mock -d -h 0.0.0.0 \
stoplight/prism:4.11.0 mock -d -h 0.0.0.0 \
https://raw.githubusercontent.com/LucidtechAI/cradl-docs/master/static/oas.json \
> /tmp/prism.cid

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Download the following packages:
* The latest and greatest stable version of [MSBuild](https://aur.archlinux.org/packages/mono-msbuild-git)
* The latest and greatest version of [NuGet](https://aur.archlinux.org/packages/nuget3/)
* [nunit](https://aur.archlinux.org/packages/nunit3-console/) version 3.9.0 or higher to run tests from command line
* [.NET-SDK](https://www.archlinux.org/packages/community/x86_64/dotnet-sdk/) version 2.2.105
* [.NET-SDK](https://wiki.archlinux.org/title/.NET) version 7.0.113


### Build and run tests
Clone repo and install the necessary packages manually for the las-sdk-net.
Expand Down
6 changes: 3 additions & 3 deletions Test/Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public static string[] ExpectedKeys(string resourceName) {
case "datasets":
return new[] {"datasets", "nextToken"};
case "document":
return new [] {"documentId", "contentType", "consentId", "groundTruth"};
return new [] {"documentId", "groundTruth"};
case "documents":
return new [] {"nextToken", "documents"};
case "logs":
return new[] {"logs", "nextToken"};
case "model":
return new[] {"modelId", "name", "description", "height", "width", "preprocessConfig", "fieldConfig", "status", "createdTime", "updatedTime"};
return new[] {"modelId", "name", "description", "preprocessConfig", "fieldConfig", "status", "createdTime", "updatedTime"};
case "models":
return new[] {"models", "nextToken"};
case "dataBundle":
Expand All @@ -60,7 +60,7 @@ public static string[] ExpectedKeys(string resourceName) {
case "heartbeats":
return new [] {"Your request executed successfully"};
case "user":
return new [] {"userId", "name", "avatar", "email"};
return new [] {"userId"};
case "users":
return new [] {"nextToken", "users"};
case "workflow":
Expand Down
Loading

0 comments on commit c760b73

Please sign in to comment.