Skip to content

Add deferrable mode to EmrServerlessJobSensor - #71652

Merged
o-nikolas merged 5 commits into
apache:mainfrom
saadbelgi:make-emr-serverless-sensor-deferrable
Sep 16, 2026
Merged

o-nikolas merged 5 commits into
apache:mainfrom
saadbelgi:make-emr-serverless-sensor-deferrable

Conversation

@saadbelgi

@saadbelgi saadbelgi commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Add deferrable mode to EmrServerlessJobSensor so waiting on a long-running EMR Serverless job does not occupy a worker slot.

Follows EmrJobFlowSensor / EmrStepSensor: poke once, then defer() to a dedicated EmrServerlessJobSensorTrigger. The trigger uses the existing serverless_job_completed waiter with acceptors overridden to preserve the sensor's configured target_states. Poke/reschedule behaviour is unchanged when deferrable=False.

Docs: class docstring plus providers/amazon/docs/operators/emr/emr_serverless.rst.

Implementation notes

  • Waiter configuration overrides: The trigger reuses the existing serverless_job_completed waiter and overrides only its acceptors. A static waiter cannot represent runtime-configurable target_states, so this avoids adding separate waiter JSON for each possible target-state combination.
  • Failure exceptions: poke() still raises AirflowException on JOB_FAILURE_STATES, as before. execute_complete() raises RuntimeError because new direct raise AirflowException usages are blocked by the check-no-new-airflow-exceptions pre-commit hook. This also follows the existing DynamoDB and SSM sensor patterns.
  • Dedicated trigger: EmrServerlessStartJobTrigger remains unchanged for EmrServerlessStartJobOperator. The new EmrServerlessJobSensorTrigger is sensor-specific because it must support runtime-configurable target_states and sensor timeout semantics.

Was generative AI tooling used to co-author this PR?
  • Yes — Cursor Grok 4.5

Generated-by: Cursor Grok 4.5 following the guidelines


Tests run locally

  • prek (pre-commit): passed, including ruff, ruff-format, and check-no-new-airflow-exceptions on the changed files.
  • mypy: breeze run mypy providers/amazon/src/airflow/providers/amazon/aws/sensors/emr.py providers/amazon/src/airflow/providers/amazon/aws/triggers/emr.py — passed
  • Sensor + EMR trigger unit tests: breeze testing providers-tests --python 3.10 providers/amazon/tests/unit/amazon/aws/sensors/test_emr_serverless_job.py providers/amazon/tests/unit/amazon/aws/triggers/test_emr.py providers/amazon/tests/unit/amazon/aws/triggers/test_serialization.py -xvs — passed
  • Amazon provider suite: breeze testing providers-tests --python 3.10 --test-type "Providers[amazon]" — passed

@boring-cyborg

boring-cyborg Bot commented Aug 15, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://s.apache.org/airflow-slack

@boring-cyborg boring-cyborg Bot added the provider:amazon AWS/Amazon - related issues label Aug 15, 2026
@saadbelgi
saadbelgi force-pushed the make-emr-serverless-sensor-deferrable branch 3 times, most recently from 07bcef2 to 8e9f617 Compare August 16, 2026 15:22
@saadbelgi
saadbelgi marked this pull request as ready for review August 16, 2026 18:58
@saadbelgi
saadbelgi requested a review from o-nikolas as a code owner August 16, 2026 18:58

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think there are 2 main concerns that should be addressed. I have left comments.

@saadbelgi
saadbelgi force-pushed the make-emr-serverless-sensor-deferrable branch 2 times, most recently from 55ae61a to edeb640 Compare September 2, 2026 20:20

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending green CI. But this needs one of the AWS maintainers to look at it before merge.

@saadbelgi
saadbelgi force-pushed the make-emr-serverless-sensor-deferrable branch 4 times, most recently from 7e576db to 1a9ea35 Compare September 8, 2026 09:39
@saadbelgi
saadbelgi force-pushed the make-emr-serverless-sensor-deferrable branch from 1a9ea35 to fa9db33 Compare September 11, 2026 19:07
@saadbelgi
saadbelgi force-pushed the make-emr-serverless-sensor-deferrable branch from fa9db33 to bcc4c9c Compare September 11, 2026 19:12
@eladkal
eladkal requested a review from vincbeck September 15, 2026 14:09
@o-nikolas
o-nikolas merged commit a80151b into apache:main Sep 16, 2026
83 checks passed
@boring-cyborg

boring-cyborg Bot commented Sep 16, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants