Skip to content
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

Merged
merged 10 commits into from
Nov 9, 2024
Merged

Conversation

abiisnn
Copy link
Contributor

@abiisnn abiisnn commented Oct 25, 2024

Description

Currently, the Orchestrator job completes before the processing jobs are completed, it will incorrectly not allow cancel of an import because it thinks the job is done. This is incorrect as the Orchestrator is done but not the child Processing Jobs,.

This PR is fixing this issue, now we check all jobs to check the status of all jobs.

Related issues

Addresses issue #124093

Testing

Added a test to make sure it first returns Accepted status to cancel request, which means the import job has been cancelled, and then make sure we received Conflict status if we have already cancelled the job.

The existing test was making sure that the cancel operation works if all jobs have already completed (with just one patient) it was happening.

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

@abiisnn abiisnn added this to the S153 milestone Oct 30, 2024
@abiisnn abiisnn added Bug Bug bug bug. Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Open source This change is only relevant to the OSS code or release. Schema Version unchanged labels Oct 30, 2024
@abiisnn abiisnn marked this pull request as ready for review October 30, 2024 21:22
@abiisnn abiisnn requested a review from a team as a code owner October 30, 2024 21:22
Copy link
Contributor Author

@abiisnn abiisnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/azp run

@@ -66,14 +66,26 @@ public async Task GivenAFhirMediator_WhenCancelingExistingBulkImportJobThatHasAl
Assert.Equal(HttpStatusCode.Conflict, operationFailedException.ResponseStatusCode);
}

[Theory]
[InlineData(JobStatus.Cancelled)]
public async Task GivenAFhirMediator_WhenCancelingExistingBulkImportJobThatHasAlreadyBeenCanceled_ThenAcceptedStatusCodeShouldBeReturned(JobStatus taskStatus)
Copy link
Contributor Author

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.

Copy link
Contributor

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

{
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)
Copy link
Contributor Author

@abiisnn abiisnn Oct 31, 2024

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to check w/ PM on behavior change

@SergeyGaluzo
Copy link
Contributor

I don't think jobs == null condition needs to be checked.

@SergeyGaluzo
Copy link
Contributor

I think it would be easier to use Linq instead of foreach.

mikaelweave
mikaelweave previously approved these changes Nov 1, 2024
Copy link
Contributor

@mikaelweave mikaelweave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with some suggestions

@@ -66,14 +66,26 @@ public async Task GivenAFhirMediator_WhenCancelingExistingBulkImportJobThatHasAl
Assert.Equal(HttpStatusCode.Conflict, operationFailedException.ResponseStatusCode);
}

[Theory]
[InlineData(JobStatus.Cancelled)]
public async Task GivenAFhirMediator_WhenCancelingExistingBulkImportJobThatHasAlreadyBeenCanceled_ThenAcceptedStatusCodeShouldBeReturned(JobStatus taskStatus)
Copy link
Contributor

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

{
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just need to check w/ PM on behavior change

Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

// Wait for import job to complete
await Task.Delay(TimeSpan.FromSeconds(10));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I worry this could create a flake test in the future.

Could we check the status of the import before moving forward in the test?

We could even loop and wait again if it's not complete (up to 5 times or so).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@abiisnn abiisnn changed the title Fix CancelImport request Fix Cancel Import Request Nov 1, 2024
mikaelweave
mikaelweave previously approved these changes Nov 1, 2024
Copy link
Contributor Author

@abiisnn abiisnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/azp run

Uri checkLocation = await ImportTestHelper.CreateImportTaskAsync(_client, request);

// Wait for import job to complete
await Task.Delay(TimeSpan.FromSeconds(10));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

@abiisnn
Copy link
Contributor Author

abiisnn commented Nov 4, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@abiisnn
Copy link
Contributor Author

abiisnn commented Nov 8, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@abiisnn abiisnn force-pushed the abigailn/fix_cancelImportRequestHandler branch from b3b105e to e07748b Compare November 8, 2024 21:50
@abiisnn abiisnn enabled auto-merge (squash) November 8, 2024 22:11
@abiisnn abiisnn merged commit e891cea into main Nov 9, 2024
47 checks passed
@abiisnn abiisnn deleted the abigailn/fix_cancelImportRequestHandler branch November 9, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Bug Bug bug bug. Open source This change is only relevant to the OSS code or release. Schema Version unchanged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants