Skip to content

Commit e807844

Browse files
committed
fix file deletion from storage
Signed-off-by: Sam Rooke <[email protected]>
1 parent ec289c4 commit e807844

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/WorkflowManager/Common/Services/PayloadService.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public PayloadService(
8787
Timestamp = eventPayload.Timestamp,
8888
PatientDetails = patientDetails,
8989
PayloadDeleted = PayloadDeleted.No,
90+
Files = eventPayload.Payload.ToList()
9091
};
9192

9293
if (await _payloadRepository.CreateAsync(payload))
@@ -173,12 +174,12 @@ public async Task<bool> DeletePayloadFromStorageAsync(string payloadId)
173174
throw new MonaiNotFoundException($"Payload with ID: {payloadId} not found");
174175
}
175176

176-
if (payload.PayloadDeleted == PayloadDeleted.InProgress)
177+
if (payload.PayloadDeleted == PayloadDeleted.InProgress || payload.PayloadDeleted == PayloadDeleted.Yes)
177178
{
178-
throw new MonaiBadRequestException($"Deletion of files for payload ID: {payloadId} already in progress");
179+
throw new MonaiBadRequestException($"Deletion of files for payload ID: {payloadId} already in progress or already deleted");
179180
}
180181

181-
// update the payload to in progress before we request deletion form MinIO
182+
// update the payload to in progress before we request deletion from storage
182183
payload.PayloadDeleted = PayloadDeleted.InProgress;
183184
await _payloadRepository.UpdateAsync(payload);
184185

@@ -188,12 +189,19 @@ public async Task<bool> DeletePayloadFromStorageAsync(string payloadId)
188189
{
189190
try
190191
{
191-
await _storageService.RemoveObjectsAsync(payload.Bucket, payload.Files.Select(f => f.Path));
192+
// get all objects for the payload in storage to be deleted
193+
var allPayloadObjects = await _storageService.ListObjectsAsync(payload.Bucket, payloadId, true);
194+
195+
if (allPayloadObjects.Any())
196+
{
197+
await _storageService.RemoveObjectsAsync(payload.Bucket, allPayloadObjects.Select(o => o.FilePath));
198+
}
199+
192200
payload.PayloadDeleted = PayloadDeleted.Yes;
193201
}
194-
catch
202+
catch (Exception ex)
195203
{
196-
_logger.PayloadUpdateFailed(payloadId);
204+
_logger.PayloadDeleteFailed(payloadId, ex);
197205
payload.PayloadDeleted = PayloadDeleted.Failed;
198206
}
199207
finally

src/WorkflowManager/Logging/Log.300000.Payload.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ public static partial class Log
3737

3838
[LoggerMessage(EventId = 300005, Level = LogLevel.Error, Message = "Failed to update payload {payloadId} due to database error.")]
3939
public static partial void PayloadUpdateFailed(this ILogger logger, string payloadId);
40+
41+
[LoggerMessage(EventId = 300006, Level = LogLevel.Error, Message = "Failed to delete payload {payloadId} from storage.")]
42+
public static partial void PayloadDeleteFailed(this ILogger logger, string payloadId, Exception ex);
4043
}
4144
}

tests/IntegrationTests/WorkflowExecutor.IntegrationTests/Features/PayloadApi.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Scenario Outline: Delete payload by ID returns 400 when PayloadDeleted is alread
145145
And I have a payload saved in mongo Payload_PayloadDeleted_InProgress
146146
When I send a DELETE request
147147
Then I will get a 400 response
148-
And I will receive the error message Deletion of files for payload ID: c5c3635b-81dd-44a9-8c3b-71adec7d47c6 already in progress
148+
And I will receive the error message Deletion of files for payload ID: c5c3635b-81dd-44a9-8c3b-71adec7d47c6 already in progress or already deleted
149149

150150
@DeletePayloadById
151151
Scenario Outline: Delete payload by ID returns 202

0 commit comments

Comments
 (0)