') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Migrate EmrServerlessStartJobTrigger from CancelledError to on_kill() by riyanmohmmeed-dev · Pull Request #65740 · apache/airflow · GitHub
Skip to content

Migrate EmrServerlessStartJobTrigger from CancelledError to on_kill() - #65740

Merged
o-nikolas merged 4 commits into
apache:mainfrom
riyanmohmmeed-dev:migrate-emr-serverless-on-kill
Apr 27, 2026
Merged

Migrate EmrServerlessStartJobTrigger from CancelledError to on_kill()#65740
o-nikolas merged 4 commits into
apache:mainfrom
riyanmohmmeed-dev:migrate-emr-serverless-on-kill

Conversation

@riyanmohmmeed-dev

Copy link
Copy Markdown
Contributor

Migrate EmrServerlessStartJobTrigger from the old asyncio.CancelledError catch pattern to the new BaseTrigger.on_kill() hook (added via #65590).

Changes:

  • Add async on_kill() method that cancels the EMR Serverless job only on user-initiated task kills
  • Remove the CancelledError handler from run(), letting the parent class AwsBaseWaiterTrigger.run() handle the standard waiter flow
  • Remove safe_to_cancel(), get_task_instance(), get_task_state() which are no longer needed (on_kill only fires on user kills)
  • Clean up unused imports (asyncio, AIRFLOW_V_3_0_PLUS, TaskInstanceState, etc.)
  • Update tests to directly verify on_kill() behavior

Follows the same pattern as the Databricks trigger migration in #65590.


Was generative AI tooling used to co-author this PR?
  • Yes — Gemini

Generated-by: Gemini following the guidelines

Migrate EmrServerlessStartJobTrigger from the old asyncio.CancelledError
catch pattern to the new BaseTrigger.on_kill() hook (added via apache#65590).
Changes:
- Add async on_kill() method that cancels the EMR Serverless job
only on user-initiated task kills
- Remove the CancelledError handler from run(), letting the parent
class AwsBaseWaiterTrigger.run() handle the standard waiter flow
- Remove safe_to_cancel(), get_task_instance(), get_task_state()
which are no longer needed (on_kill only fires on user kills)
- Clean up unused imports (asyncio, AIRFLOW_V_3_0_PLUS,
TaskInstanceState, etc.)
- Update tests to directly verify on_kill() behavior
Closes: apache#65733 (EmrServerlessStartJobTrigger part)
@boring-cyborg

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: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@vincbeck

Copy link
Copy Markdown
Contributor

We do want to keep the existing code for now for compatibility reasons. BaseTrigger.on_kill() will be part of Airflow 3.3 but the provider must be working with previous versions as well

…hook
Address review feedback from vincbeck: keep the existing
CancelledError handler in run() and safe_to_cancel() logic for
backward compatibility with Airflow < 3.3. Add on_kill() as an
additional cancellation path for Airflow 3.3+ where
BaseTrigger.on_kill() is available.
Changes:
- Restore all original code (run(), safe_to_cancel(),
get_task_instance(), get_task_state())
- Add async on_kill() that fires on user-initiated kills (3.3+)
- Add tests for on_kill() behavior
@riyanmohmmeed-dev

Copy link
Copy Markdown
ContributorAuthor

@vincbeck Thanks for pointing that out! Totally makes sense — I didn't consider that the provider needs to work with older Airflow versions too. I've updated the PR to keep all the existing code as-is and just added on_kill() on top. The diff is now purely additive. Let me know if anything else needs changing!

@vincbeckvincbeck 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.

One nit: can you add a comment saying that the old way (using CancelledError) can be removed once the min Airflow version supported by provider is >= 3.3

@vincbeck

Copy link
Copy Markdown
Contributor

Thank you! I'll merge once the CI is green

@riyanmohmmeed-dev

Copy link
Copy Markdown
ContributorAuthor

CI caught a minor ruff/pre-commit formatting discrepancy with the docstring style and line spacing. Just pushed the auto-formatted fixes, so the static checks should all run green now!

@o-nikolas
o-nikolas merged commit 2671465 into apache:mainApr 27, 2026
175 of 176 checks passed
@boring-cyborg

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providersprovider:amazonAWS/Amazon - related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@riyanmohmmeed-dev@vincbeck@o-nikolas