Skip to content

Commit ad938c7

Browse files
authored
Merge pull request #782 from Project-MONAI/AC-2127
changing from workflowInstanceId to workflowId
2 parents 51836fd + fc1c8e7 commit ad938c7

11 files changed

+132
-74
lines changed

src/WorkflowManager/Contracts/Migrations/M001_TaskExecutionStats_addVersion.cs renamed to src/WorkflowManager/Contracts/Migrations/M001_ExecutionStats_addVersion.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17-
using System;
1817
using Monai.Deploy.WorkflowManager.Contracts.Models;
1918
using Mongo.Migration.Migrations.Document;
2019
using MongoDB.Bson;
2120

2221
namespace Monai.Deploy.WorkflowManager.Contracts.Migrations
2322
{
24-
public class M001_TaskExecutionStats_addVersion : DocumentMigration<ExecutionStats>
23+
public class M001_ExecutionStats_addVersion : DocumentMigration<ExecutionStats>
2524
{
26-
public M001_TaskExecutionStats_addVersion() : base("1.0.0") { }
25+
public M001_ExecutionStats_addVersion() : base("1.0.0") { }
2726

2827
public override void Up(BsonDocument document)
2928
{
@@ -35,8 +34,8 @@ public override void Down(BsonDocument document)
3534
{
3635
document.Remove("Version");
3736
}
38-
catch (Exception)
39-
{
37+
catch
38+
{ // can ignore we dont want failures stopping startup !
4039
}
4140
}
4241
}

src/WorkflowManager/Contracts/Migrations/M001_Payload_addVerion.cs

100755100644
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
using System;
1716
using Monai.Deploy.WorkflowManager.Contracts.Models;
1817
using Mongo.Migration.Migrations.Document;
1918
using MongoDB.Bson;
@@ -34,8 +33,8 @@ public override void Down(BsonDocument document)
3433
{
3534
document.Remove("Version");
3635
}
37-
catch (Exception)
38-
{
36+
catch
37+
{ // can ignore we dont want failures stopping startup !
3938
}
4039
}
4140
}

src/WorkflowManager/Contracts/Migrations/M001_WorkflowInstance_addVerion.cs

100755100644
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
using System;
1716
using Monai.Deploy.WorkflowManager.Contracts.Models;
1817
using Mongo.Migration.Migrations.Document;
1918
using MongoDB.Bson;
@@ -34,8 +33,8 @@ public override void Down(BsonDocument document)
3433
{
3534
document.Remove("Version");
3635
}
37-
catch (Exception)
38-
{
36+
catch
37+
{ // can ignore we dont want failures stopping startup !
3938
}
4039
}
4140
}

src/WorkflowManager/Contracts/Migrations/M001_WorkflowRevision_addVerion.cs

100755100644
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
using System;
1716
using Monai.Deploy.WorkflowManager.Contracts.Models;
1817
using Mongo.Migration.Migrations.Document;
1918
using MongoDB.Bson;
@@ -34,8 +33,8 @@ public override void Down(BsonDocument document)
3433
{
3534
document.Remove("Version");
3635
}
37-
catch (Exception)
38-
{
36+
catch
37+
{ // can ignore we dont want failures stopping startup !
3938
}
4039
}
4140
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 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+
using Mongo.Migration.Migrations.Document;
19+
using MongoDB.Bson;
20+
21+
namespace Monai.Deploy.WorkflowManager.Contracts.Migrations
22+
{
23+
public class M002_ExecutionStats_addWorkflowId : DocumentMigration<ExecutionStats>
24+
{
25+
public M002_ExecutionStats_addWorkflowId() : base("1.0.1") { }
26+
27+
public override void Up(BsonDocument document)
28+
{
29+
// empty, but this will make all objects re-saved with a workflowId
30+
}
31+
public override void Down(BsonDocument document)
32+
{
33+
try
34+
{
35+
document.Remove("WorkflowId");
36+
}
37+
catch
38+
{ // can ignore we dont want failures stopping startup !
39+
}
40+
}
41+
}
42+
}

src/WorkflowManager/Contracts/Migrations/M002_Payload_addPayloadDeleted.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
using System;
1716
using Monai.Deploy.WorkflowManager.Contracts.Models;
1817
using Mongo.Migration.Migrations.Document;
1918
using MongoDB.Bson;
@@ -35,8 +34,8 @@ public override void Down(BsonDocument document)
3534
{
3635
document.Remove("PayloadDeleted");
3736
}
38-
catch (Exception)
39-
{
37+
catch
38+
{ // can ignore we dont want failures stopping startup !
4039
}
4140
}
4241
}

src/WorkflowManager/Contracts/Models/ExecutionStats.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace Monai.Deploy.WorkflowManager.Contracts.Models
2828
{
29-
[CollectionLocation("ExecutionStats"), RuntimeVersion("1.0.0")]
29+
[CollectionLocation("ExecutionStats"), RuntimeVersion("1.0.1")]
3030
public class ExecutionStats : IDocument
3131
{
3232
/// <summary>
@@ -40,7 +40,7 @@ public class ExecutionStats : IDocument
4040
/// Gets or sets Db version.
4141
/// </summary>
4242
[JsonConverter(typeof(DocumentVersionConvert)), BsonSerializer(typeof(DocumentVersionConverBson))]
43-
public DocumentVersion Version { get; set; } = new DocumentVersion(1, 0, 0);
43+
public DocumentVersion Version { get; set; } = new DocumentVersion(1, 0, 1);
4444

4545
/// <summary>
4646
/// the correlationId of the event
@@ -49,6 +49,13 @@ public class ExecutionStats : IDocument
4949
[Required]
5050
public string CorrelationId { get; set; } = "";
5151

52+
/// <summary>
53+
/// The id of the workflow
54+
/// </summary>
55+
[JsonProperty(PropertyName = "workflow_id")]
56+
[Required]
57+
public string WorkflowId { get; set; } = "";
58+
5259
/// <summary>
5360
/// the workflow Instance that triggered the event
5461
/// </summary>
@@ -117,7 +124,7 @@ public ExecutionStats()
117124

118125
}
119126

120-
public ExecutionStats(TaskExecution execution, string correlationId)
127+
public ExecutionStats(TaskExecution execution, string workflowId, string correlationId)
121128
{
122129
Guard.Against.Null(execution, "dispatchInfo");
123130
CorrelationId = correlationId;
@@ -126,26 +133,29 @@ public ExecutionStats(TaskExecution execution, string correlationId)
126133
TaskId = execution.TaskId;
127134
StartedUTC = execution.TaskStartTime.ToUniversalTime();
128135
Status = execution.Status.ToString();
136+
WorkflowId = workflowId;
129137
}
130138

131-
public ExecutionStats(TaskUpdateEvent taskUpdateEvent)
139+
public ExecutionStats(TaskUpdateEvent taskUpdateEvent, string workflowId)
132140
{
133141
Guard.Against.Null(taskUpdateEvent, "taskUpdateEvent");
134142
CorrelationId = taskUpdateEvent.CorrelationId;
135143
WorkflowInstanceId = taskUpdateEvent.WorkflowInstanceId;
136144
ExecutionId = taskUpdateEvent.ExecutionId;
137145
TaskId = taskUpdateEvent.TaskId;
138146
Status = taskUpdateEvent.Status.ToString();
147+
WorkflowId = workflowId;
139148
}
140149

141-
public ExecutionStats(TaskCancellationEvent taskCanceledEvent, string correlationId)
150+
public ExecutionStats(TaskCancellationEvent taskCanceledEvent, string workflowId, string correlationId)
142151
{
143152
Guard.Against.Null(taskCanceledEvent, "taskCanceledEvent");
144153
CorrelationId = correlationId;
145154
WorkflowInstanceId = taskCanceledEvent.WorkflowInstanceId;
146155
ExecutionId = taskCanceledEvent.ExecutionId;
147156
TaskId = taskCanceledEvent.TaskId;
148157
Status = TaskExecutionStatus.Failed.ToString();
158+
WorkflowId = workflowId;
149159
}
150160
}
151161
}

src/WorkflowManager/Database/Interfaces/ITaskExecutionStatsRepository.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ public interface ITaskExecutionStatsRepository
2929
/// </summary>
3030
/// <param name="taskDispatchEvent">A TaskDispatchEvent to create.</param>
3131
/// <returns></returns>
32-
Task CreateAsync(TaskExecution TaskExecutionInfo, string correlationId);
32+
Task CreateAsync(TaskExecution TaskExecutionInfo, string workflowId, string correlationId);
3333

3434
/// <summary>
3535
/// Updates status of a task dispatch event in the database.
3636
/// </summary>
3737
/// <param name="taskDispatchEvent">A TaskDispatchEvent to update.</param>
3838
/// <returns></returns>
39-
Task UpdateExecutionStatsAsync(TaskExecution taskUpdateEvent, TaskExecutionStatus? status = null);
39+
Task UpdateExecutionStatsAsync(TaskExecution taskUpdateEvent, string workflowId, TaskExecutionStatus? status = null);
4040

4141
/// <summary>
4242
/// Updates status of a task now its been canceled.
4343
/// </summary>
4444
/// <param name="TaskCanceledException">A TaskCanceledException to update.</param>
4545
/// <returns></returns
46-
Task UpdateExecutionStatsAsync(TaskCancellationEvent taskCanceledEvent, string correlationId);
46+
Task UpdateExecutionStatsAsync(TaskCancellationEvent taskCanceledEvent, string workflowId, string correlationId);
4747

4848
/// <summary>
4949
/// Returns paged entries between the two given dates.
5050
/// </summary>
5151
/// <param name="startTime">start of the range.</param>
5252
/// <param name="endTime">end of the range.</param>
5353
/// <returns>a collections of stats</returns>
54-
Task<IEnumerable<ExecutionStats>> GetStatsAsync(DateTime startTime, DateTime endTime, int PageSize = 10, int PageNumber = 1, string workflowInstanceId = "", string taskId = "");
54+
Task<IEnumerable<ExecutionStats>> GetStatsAsync(DateTime startTime, DateTime endTime, int PageSize = 10, int PageNumber = 1, string workflowId = "", string taskId = "");
5555

5656
/// <summary>
5757
/// Return the total number of stats between the dates
5858
/// </summary>
5959
/// <param name="startTime">start of the range.</param>
6060
/// <param name="endTime">end of the range.</param>
6161
/// <returns>The count of all records in range</returns>
62-
//Task<long> GetStatsCountAsync(DateTime startTime, DateTime endTime, string workflowInstanceId = "", string taskId = "");
62+
//Task<long> GetStatsCountAsync(DateTime startTime, DateTime endTime, string workflowId = "", string taskId = "");
6363

6464
/// <summary>
6565
/// Return the count of the entries with this status, or all if no status given
@@ -68,23 +68,23 @@ public interface ITaskExecutionStatsRepository
6868
/// <param name="endTime">end of the range.</param>
6969
/// <param name="status">the status to get count of, or string.empty</param>
7070
/// <returns>The count of all records in range</returns>
71-
Task<long> GetStatsStatusCountAsync(DateTime start, DateTime endTime, string status = "", string workflowInstanceId = "", string taskId = "");
71+
Task<long> GetStatsStatusCountAsync(DateTime start, DateTime endTime, string status = "", string workflowId = "", string taskId = "");
7272

7373
/// <summary>
7474
/// Returns all stats in Failed or PartialFail status.
7575
/// </summary>
7676
/// <param name="startTime">start of the range.</param>
7777
/// <param name="endTime">end of the range.</param>
7878
/// <returns>All stats that failed or partially failed</returns>
79-
Task<long> GetStatsStatusFailedCountAsync(DateTime startTime, DateTime endTime, string workflowInstanceId = "", string taskId = "");
79+
Task<long> GetStatsStatusFailedCountAsync(DateTime startTime, DateTime endTime, string workflowId = "", string taskId = "");
8080

8181
/// <summary>
8282
/// Calculates the average exection time for the given range
8383
/// </summary>
8484
/// <param name="startTime">start of the range.</param>
8585
/// <param name="endTime">end of the range.</param>
8686
/// <returns>the average exection times in the time range</returns>
87-
Task<(double avgTotalExecution, double avgArgoExecution)> GetAverageStats(DateTime startTime, DateTime endTime, string workflowInstanceId = "", string taskId = "");
87+
Task<(double avgTotalExecution, double avgArgoExecution)> GetAverageStats(DateTime startTime, DateTime endTime, string workflowId = "", string taskId = "");
8888

8989
}
9090
}

0 commit comments

Comments
 (0)