Skip to content

Commit e0a3f80

Browse files
authored
64 tasks api (#266)
* TasksApi implementation Signed-off-by: Lillie Dae <[email protected]>
1 parent fadac35 commit e0a3f80

File tree

22 files changed

+814
-29
lines changed

22 files changed

+814
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,3 +576,4 @@ GitExtensions.settings.backup
576576
*.AssemblyHooks.cs
577577
*.AssemblyHooks.vb
578578
/src/WorkflowManager/mc.exe
579+
*.lutconfig

src/Common/Interfaces/IPayloadService.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Monai.Deploy.WorkflowManager.Common.Interfaces
2121
{
22-
public interface IPayloadService
22+
public interface IPayloadService : IPaginatedApi<Payload>
2323
{
2424
/// <summary>
2525
/// Creates a payload and appends patient details.
@@ -41,12 +41,6 @@ Task<IList<Payload>> GetAllAsync(int? skip = null,
4141
string? patientId = "",
4242
string? patientName = "");
4343

44-
/// <summary>
45-
/// Gets Count of objects
46-
/// </summary>
47-
/// <returns>the count of objects</returns>
48-
Task<long> CountAsync();
49-
5044
/// <summary>
5145
/// Updates a payload
5246
/// </summary>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Monai.Deploy.WorkflowManager.Contracts.Models;
18+
19+
namespace Monai.Deploy.WorkflowManager.Common.Interfaces
20+
{
21+
public interface ITasksService : IPaginatedApi<TaskExecution>
22+
{
23+
Task<TaskExecution?> GetTaskAsync(string workflowInstanceId, string taskId, string executionId);
24+
}
25+
}

src/Common/Services/PayloadService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace Monai.Deploy.WorkflowManager.Common.Services
2727
{
28-
public class PayloadService : IPayloadService, IPaginatedApi<Payload>
28+
public class PayloadService : IPayloadService
2929
{
3030
private readonly IPayloadRepsitory _payloadRepsitory;
3131

@@ -95,6 +95,5 @@ public async Task<IList<Payload>> GetAllAsync(int? skip = null, int? limit = nul
9595

9696
public async Task<bool> UpdateWorkflowInstanceIdsAsync(string payloadId, IEnumerable<string> workflowInstances)
9797
=> await _payloadRepsitory.UpdateAssociatedWorkflowInstancesAsync(payloadId, workflowInstances);
98-
9998
}
10099
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Monai.Deploy.WorkflowManager.Common.Interfaces;
18+
using Monai.Deploy.WorkflowManager.Database.Interfaces;
19+
using Monai.Deploy.WorkflowManager.Contracts.Models;
20+
21+
namespace Monai.Deploy.WorkflowManager.Common.Services
22+
{
23+
public class TasksService : ITasksService
24+
{
25+
private readonly ITasksRepository _tasksRepository;
26+
27+
public TasksService(ITasksRepository workflowInstanceRepository)
28+
{
29+
_tasksRepository = workflowInstanceRepository ?? throw new ArgumentNullException(nameof(workflowInstanceRepository));
30+
}
31+
32+
/// <summary>
33+
/// Not Required For Tasks Service is
34+
/// </summary>
35+
/// <returns></returns>
36+
/// <exception cref="NotImplementedException"></exception>
37+
public async Task<long> CountAsync()
38+
=> await _tasksRepository.CountAsync();
39+
40+
/// <summary>
41+
/// Gets all running tasks
42+
/// </summary>
43+
/// <param name="skip"></param>
44+
/// <param name="limit"></param>
45+
/// <returns></returns>
46+
public async Task<IList<TaskExecution>> GetAllAsync(int? skip = null, int? limit = null)
47+
=> await _tasksRepository.GetAllAsync(skip, limit);
48+
49+
/// <summary>
50+
/// Gets task by WorkflowInstanceId, TaskId, ExecutionId.
51+
/// </summary>
52+
/// <param name="workflowInstanceId">Instance Id.</param>
53+
/// <param name="taskId">Task Id.</param>
54+
/// <param name="executionId">Execution Id.</param>
55+
/// <returns></returns>
56+
public async Task<TaskExecution?> GetTaskAsync(string workflowInstanceId, string taskId, string executionId)
57+
=> await _tasksRepository.GetTaskAsync(workflowInstanceId, taskId, executionId);
58+
}
59+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Newtonsoft.Json;
18+
using System;
19+
using System.Collections.Generic;
20+
21+
namespace Monai.Deploy.WorkflowManager.Contracts.Models
22+
{
23+
public class WorkflowInstanceTasksUnwindResult
24+
{
25+
[JsonProperty(PropertyName = "id")]
26+
public string Id { get; set; } = string.Empty;
27+
28+
[JsonProperty(PropertyName = "ae_title")]
29+
public string AeTitle { get; set; } = string.Empty;
30+
31+
[JsonProperty(PropertyName = "workflow_id")]
32+
public string WorkflowId { get; set; } = string.Empty;
33+
34+
[JsonProperty(PropertyName = "payload_id")]
35+
public string PayloadId { get; set; } = string.Empty;
36+
37+
[JsonProperty(PropertyName = "start_time")]
38+
public DateTime StartTime { get; set; }
39+
40+
[JsonProperty(PropertyName = "status")]
41+
public Status Status { get; set; }
42+
43+
[JsonProperty(PropertyName = "bucket_id")]
44+
public string BucketId { get; set; } = string.Empty;
45+
46+
[JsonProperty(PropertyName = "input_metadata")]
47+
public Dictionary<string, string> InputMetaData { get; set; } = new Dictionary<string, string>();
48+
49+
[JsonProperty(PropertyName = "tasks")]
50+
public TaskExecution Tasks { get; set; }
51+
}
52+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using System.Collections.Generic;
18+
using System.Threading.Tasks;
19+
using Monai.Deploy.WorkflowManager.Contracts.Models;
20+
21+
namespace Monai.Deploy.WorkflowManager.Database.Interfaces
22+
{
23+
public interface ITasksRepository
24+
{
25+
/// <summary>
26+
/// Gets all running tasks.
27+
/// </summary>
28+
/// <param name="skip">skip.</param>
29+
/// <param name="limit">limit.</param>
30+
/// <returns></returns>
31+
Task<IList<TaskExecution>> GetAllAsync(int? skip, int? limit);
32+
33+
/// <summary>
34+
/// Gets count of Tasks.
35+
/// </summary>
36+
/// <returns></returns>
37+
Task<long> CountAsync();
38+
39+
/// <summary>
40+
/// Gets Task Execution given workflowInstanceId, taskId and executionId.
41+
/// </summary>
42+
/// <param name="workflowInstanceId">workflowInstanceId.</param>
43+
/// <param name="taskId">taskId.</param>
44+
/// <param name="executionId">executionId<./param>
45+
/// <returns></returns>
46+
Task<TaskExecution?> GetTaskAsync(string workflowInstanceId, string taskId, string executionId);
47+
}
48+
}

src/Database/Interfaces/IWorkflowInstanceRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public interface IWorkflowInstanceRepository
4040
/// <param name="workflowInstanceId">A Workflow Instance Id to retrieve.</param>
4141
Task<WorkflowInstance> GetByWorkflowInstanceIdAsync(string workflowInstanceId);
4242

43-
43+
/// <summary>
44+
/// Gets count of Workflow Instances.
45+
/// </summary>
46+
/// <returns></returns>
4447
Task<long> CountAsync();
4548

4649
/// <summary>

src/Database/PayloadRepository.cs renamed to src/Database/Repositories/PayloadRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
using Monai.Deploy.WorkflowManager.Logging.Logging;
2727
using MongoDB.Driver;
2828

29-
namespace Monai.Deploy.WorkflowManager.Database
29+
namespace Monai.Deploy.WorkflowManager.Database.Repositories
3030
{
3131
public class PayloadRepository : RepositoryBase, IPayloadRepsitory
3232
{
@@ -48,7 +48,7 @@ public PayloadRepository(
4848
_payloadCollection = mongoDatabase.GetCollection<Payload>(databaseSettings.Value.PayloadCollectionName);
4949
}
5050

51-
public Task<long> CountAsync() => base.CountAsync(_payloadCollection, null);
51+
public Task<long> CountAsync() => CountAsync(_payloadCollection, null);
5252

5353
public async Task<bool> CreateAsync(Payload payload)
5454
{
@@ -68,7 +68,7 @@ public async Task<bool> CreateAsync(Payload payload)
6868
}
6969
}
7070

71-
public async Task<IList<Payload>> GetAllAsync(int? skip = null, int? limit = null, string? patientId = "", string? patientName = "")
71+
public async Task<IList<Payload>> GetAllAsync(int? skip = null, int? limit = null, string patientId = "", string patientName = "")
7272
{
7373
var builder = Builders<Payload>.Filter;
7474
var filter = builder.Empty;
@@ -81,7 +81,7 @@ public async Task<IList<Payload>> GetAllAsync(int? skip = null, int? limit = nul
8181
filter &= builder.Eq(p => p.PatientDetails.PatientName, patientName);
8282
}
8383

84-
return await base.GetAllAsync(_payloadCollection,
84+
return await GetAllAsync(_payloadCollection,
8585
filter,
8686
Builders<Payload>.Sort.Descending(x => x.Timestamp),
8787
skip,

src/Database/RepositoryBase.cs renamed to src/Database/Repositories/RepositoryBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
using System.Threading.Tasks;
2121
using MongoDB.Driver;
2222

23-
namespace Monai.Deploy.WorkflowManager.Database
23+
namespace Monai.Deploy.WorkflowManager.Database.Repositories
2424
{
2525
public abstract class RepositoryBase
2626
{
27-
public async Task<long> CountAsync<T>(IMongoCollection<T> collection, Expression<Func<T, bool>>? filterFunction)
27+
public static async Task<long> CountAsync<T>(IMongoCollection<T> collection, Expression<Func<T, bool>>? filterFunction)
2828
=> await collection.CountDocumentsAsync(filterFunction ?? Builders<T>.Filter.Empty);
2929

3030
/// <summary>
@@ -37,7 +37,7 @@ public async Task<long> CountAsync<T>(IMongoCollection<T> collection, Expression
3737
/// <param name="skip">Items to skip.</param>
3838
/// <param name="limit">Items to limit results by.</param>
3939
/// <returns></returns>
40-
public async Task<IList<T>> GetAllAsync<T>(IMongoCollection<T> collection, Expression<Func<T, bool>>? filterFunction, SortDefinition<T> sortFunction, int? skip = null, int? limit = null)
40+
public static async Task<IList<T>> GetAllAsync<T>(IMongoCollection<T> collection, Expression<Func<T, bool>> filterFunction, SortDefinition<T> sortFunction, int? skip = null, int? limit = null)
4141
{
4242
return await collection
4343
.Find(filterFunction ?? Builders<T>.Filter.Empty)
@@ -47,7 +47,7 @@ public async Task<IList<T>> GetAllAsync<T>(IMongoCollection<T> collection, Expre
4747
.ToListAsync();
4848
}
4949

50-
public async Task<IList<T>> GetAllAsync<T>(IMongoCollection<T> collection, FilterDefinition<T> filterFunction, SortDefinition<T> sortFunction, int? skip = null, int? limit = null)
50+
public static async Task<IList<T>> GetAllAsync<T>(IMongoCollection<T> collection, FilterDefinition<T> filterFunction, SortDefinition<T> sortFunction, int? skip = null, int? limit = null)
5151
{
5252
return await collection
5353
.Find(filterFunction)

0 commit comments

Comments
 (0)