damccorm commented on code in PR #41627:
URL: https://github.com/apache/beam/pull/41627#discussion_r4700114888
##########
sdks/python/apache_beam/runners/dataflow/internal/apiclient.py:
##########
@@ -956,9 +966,35 @@ def modify_job_state(self, job_id, new_state) -> bool:
request.job_id = job_id
request.project_id = self.google_cloud_options.project
request.location = self.google_cloud_options.region
- request.job = dataflow.Job(requested_state=new_state)
+ request.job = dataflow.Job(requested_state=requested_state)
+
+ def _should_retry(exception):
+ if retry.retry_on_server_errors_filter(exception):
+ return True
+ if (requested_state == dataflow.JobState.JOB_STATE_CANCELLED and
+ isinstance(exception, exceptions.FailedPrecondition)):
+ try:
+ current_state = self.get_job(job_id).current_state
+ except Exception as get_job_exn: # pylint: disable=broad-except
+ _LOGGER.warning(
+ 'Unable to fetch job %s state after FailedPrecondition on '
+ 'cancel; will not retry: %s',
+ job_id,
+ get_job_exn)
+ return False
+ return current_state not in _NON_RETRYABLE_CANCEL_STATES
Review Comment:
Thanks for catching this edge case! Keeping `modify_job_state` strict
(re-raising `FailedPrecondition` when the job is already `JOB_STATE_CANCELLED`
/ `JOB_STATE_CANCELLING` or terminal) preserves the existing low-level
`DataflowApplicationClient` contract where returning `True` means the
`update_job` RPC itself succeeded, leaving higher-level terminal-state handling
to callers like `DataflowPipelineResult.cancel()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]