Skip to content

Comments

Job status endpoint#5404

Draft
LTA-Thinking wants to merge 3 commits intomainfrom
personal/rojo/jobstatus
Draft

Job status endpoint#5404
LTA-Thinking wants to merge 3 commits intomainfrom
personal/rojo/jobstatus

Conversation

@LTA-Thinking
Copy link
Contributor

Description

Describe the changes in this PR.

Related issues

Addresses [issue #].

Testing

Describe how this change was tested.

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.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch|Skip|Feature|Breaking (reason)

Comment on lines +117 to +120
catch (Exception ex)
{
_logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.

Copilot Autofix

AI 4 minutes ago

General approach: replace the generic catch (Exception ex) with more specific catches for the exceptions we expect from SQL operations (e.g., SqlException, InvalidOperationException, DataException) and ensure we do not swallow cancellation-related exceptions such as OperationCanceledException or TaskCanceledException.

Best single fix for this snippet:

  • In GetJobsByQueueTypeAsync, replace catch (Exception ex) with one or more specific catches for SQL/data errors, plus an optional filtered catch for TaskCanceledException that rethrows if the provided CancellationToken was signaled.
  • For example:
    • catch (SqlException ex) – log warning and return current jobs list (preserves current behavior for SQL issues).
    • catch (InvalidOperationException ex) and/or catch (DataException ex) – likewise logged as warnings, since these are also typical data-access issues.
    • Optionally, allow OperationCanceledException and other non-data exceptions to bubble up, which is safer and more correct.

This can be implemented entirely within GetJobsByQueueTypeAsync in src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs. Necessary pieces:

  • No new imports are needed: SqlException is already available via Microsoft.Data.SqlClient;, and DataException is already available via using System.Data;.
  • We just add multiple catch blocks in place of the single generic one.
Suggested changeset 1
src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs b/src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs
--- a/src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs
+++ b/src/Microsoft.Health.Fhir.SqlServer/Features/Operations/SqlJobStatusService.cs
@@ -110,10 +110,18 @@
                     jobs.Add(jobStatusInfo);
                 }
             }
-            catch (Exception ex)
+            catch (SqlException ex)
             {
                 _logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
             }
+            catch (InvalidOperationException ex)
+            {
+                _logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
+            }
+            catch (DataException ex)
+            {
+                _logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
+            }
 
             return jobs;
         }
EOF
@@ -110,10 +110,18 @@
jobs.Add(jobStatusInfo);
}
}
catch (Exception ex)
catch (SqlException ex)
{
_logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
}
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
}
catch (DataException ex)
{
_logger.LogWarning(ex, "Error retrieving jobs for queue type {QueueType}", queueType);
}

return jobs;
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant