Skip to content

Allow DataflowJobStatusSensor to wait on a job name - #73356

Closed
namanjain24-sudo wants to merge 2 commits into
apache:mainfrom
namanjain24-sudo:dataflow-job-status-sensor-job-name
Closed

namanjain24-sudo wants to merge 2 commits into
apache:mainfrom
namanjain24-sudo:dataflow-job-status-sensor-job-name

Conversation

@namanjain24-sudo

Copy link
Copy Markdown
Contributor

DataflowJobStatusSensor and DataflowJobStatusTrigger can only watch a job by id. When the job is launched outside the Dag, as in #72875 where it is started from a Cloud Run job, the id is never available downstream. This adds a job_name parameter to both, mutually exclusive with job_id.

How a name is resolved:

  • Dataflow job names are not unique over time, so the new DataflowHook.get_latest_job_by_name and its async counterpart match the name exactly and return the most recent job with that name, as the issue proposes. This is deliberately not the prefix match that DataflowStopJobOperator.job_name_prefix does.
  • The match happens client side, the same way _fetch_jobs_by_prefix_name in this hook already works. Newer API clients do accept a name argument on jobs.list, but the minimum versions this provider supports do not: google-api-python-client 2.0.2's bundled discovery document and ListJobsRequest in google-cloud-dataflow-client 0.8.6 have no such field. Switching to the server-side filter would need both floors raised, and I can do that here or as a follow-up if preferred.
  • jobs.list only promises the summary view, which documents a start time but not a create time. So the ordering key is createTime, then startTime, then the job that is not in a terminal state (only one active job per name can exist in a project and region). Ordering by createTime alone made the sync path return whichever job the API listed first, and made the async path raise TypeError comparing two unset timestamps. Both cases have tests.
  • While no job with the name exists yet, the sensor keeps poking and the trigger keeps polling, so the Dag can start waiting before the job is created. A finished job from an earlier run with the same name also counts, so the docs suggest making reused names unique per run, e.g. daily-etl-{{ ds_nodash }}.

Compatibility: job_name is appended last in the trigger signature, so existing positional calls keep working, and a serialized trigger from before this change (no job_name key) still deserializes. Log messages and the terminal-state error now report the id of the job that was actually resolved.

Tests:

  • 24 new tests across the hook, sensor and trigger. With the three source files reverted to main, every one of them fails or errors.
  • The Dataflow hook, sensor, trigger and operator tests (284 passed) and the Google sensors and triggers suites (607 passed, 6 skipped) pass locally on current main. mypy is clean on the three changed modules, and the templated-fields check passes.

closes: #72875


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: a Gen-AI coding assistant, following the guidelines. I reviewed the change and ran the checks above.

@boring-cyborg boring-cyborg Bot added area:providers kind:documentation provider:google Google (including GCP) related issues labels Sep 18, 2026
@namanjain24-sudo
namanjain24-sudo marked this pull request as ready for review September 19, 2026 10:35
DataflowJobStatusSensor and DataflowJobStatusTrigger could only watch a
job by id, so a DAG that did not launch the job itself had no way to wait
for it. Add a job_name parameter to both, mutually exclusive with job_id.

Dataflow job names are not unique over time, so the new hook methods
DataflowHook.get_latest_job_by_name and its async counterpart match the
name exactly and return the most recent job with that name. This is
deliberately not the prefix match DataflowStopJobOperator.job_name_prefix
uses, because the two parameters mean different things. The Dataflow REST
API filters jobs.list by job state rather than by name, so the match has
to happen client side, the same way _fetch_jobs_by_prefix_name already
does it.

Picking the most recent one cannot rely on createTime alone. The list
method promises only the summary view, which documents a start time but
not a create time, so the ordering key falls back to startTime, and then
to the job that has not reached a terminal state, since only one active
job with a given name can exist in a project within one region at a time.
Without the fallbacks the synchronous path silently returned whichever
job the API happened to list first, and the asynchronous path raised a
TypeError comparing two unset timestamps.

While no job with that name exists yet the sensor keeps poking and the
trigger keeps polling, so a DAG can start waiting before the job is
created. Log messages and the terminal-state error now report the id of
the job that was actually resolved.
The sensor picks the most recently created job with the given name, so a
job left over from an earlier run with the same name counts as well.
Say so in the docstring and the how-to guide, and suggest making the
name unique per run.
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @namanjain24-sudo - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 7 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers closed because of open PR limit Closed as a one-time step of introducing the open pull request limit kind:documentation provider:google Google (including GCP) related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataflowJobStatusTrigger - Add param job_name

2 participants