-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Cancel Import Request #4702
Changes from all commits
7bc85be
dee11aa
f56940b
713dbc7
e0d97d7
2e741e6
4dda13d
33fd6c8
e07748b
9a011b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
@@ -43,19 +45,43 @@ public async Task<CancelImportResponse> Handle(CancelImportRequest request, Canc | |
throw new UnauthorizedFhirActionException(); | ||
} | ||
|
||
JobInfo jobInfo = await _queueClient.GetJobByIdAsync(QueueType.Import, request.JobId, false, cancellationToken); | ||
// We need to check the status of all jobs | ||
IReadOnlyList<JobInfo> jobs = await _queueClient.GetJobByGroupIdAsync(QueueType.Import, request.JobId, false, cancellationToken); | ||
|
||
if (jobInfo == null) | ||
if (jobs.Count == 0) | ||
{ | ||
throw new ResourceNotFoundException(string.Format(Core.Resources.ImportJobNotFound, request.JobId)); | ||
} | ||
|
||
if (jobInfo.Status == JobManagement.JobStatus.Completed || jobInfo.Status == JobManagement.JobStatus.Cancelled || jobInfo.Status == JobManagement.JobStatus.Failed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check that now we are not returning CONFLICT if the job has been already cancelled. Now, if the job has been already cancelled, we will retry cancel, so we will return ACCEPTED, as Sergey suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just need to check w/ PM on behavior change |
||
var anyFailed = false; | ||
var allComplete = true; | ||
|
||
// Check each job status | ||
foreach (var job in jobs) | ||
{ | ||
if (job.Status == JobStatus.Failed) | ||
{ | ||
anyFailed = true; | ||
break; | ||
} | ||
|
||
if (job.Status != JobStatus.Completed) | ||
{ | ||
allComplete = false; | ||
break; | ||
} | ||
} | ||
|
||
// If the job is already completed or failed, return conflict status. | ||
if (anyFailed || allComplete) | ||
{ | ||
throw new OperationFailedException(Core.Resources.ImportOperationCompleted, HttpStatusCode.Conflict); | ||
abiisnn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
await _queueClient.CancelJobByGroupIdAsync(QueueType.Import, jobInfo.GroupId, cancellationToken); | ||
// Try to cancel the job | ||
_logger.LogInformation("Attempting to cancel import job {JobId}", request.JobId); | ||
await _queueClient.CancelJobByGroupIdAsync(QueueType.Import, request.JobId, cancellationToken); | ||
|
||
return new CancelImportResponse(HttpStatusCode.Accepted); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new behavior, because if a tastk has been already canceled, then we will return accepted because we will continue trying to cancel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A change in behavior may require giving customers 1 month notice before deploying to prod. We should check w./ PM team