Skip to content

Add interruption reason to job_should_exit? and interrupted notification#683

Merged
SomalianIvan merged 6 commits into
mainfrom
timb/add-interruption-reason
Mar 23, 2026
Merged

Add interruption reason to job_should_exit? and interrupted notification#683
SomalianIvan merged 6 commits into
mainfrom
timb/add-interruption-reason

Conversation

@SomalianIvan

@SomalianIvan SomalianIvan commented Mar 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • job_should_exit? now returns a reason string ("max_job_runtime_exceeded", "interrupted") instead of bare true
  • The reason is included in the "interrupted.iteration" ActiveSupport::Notifications payload as reason:
  • LogSubscriber#interrupted logs the reason when present
  • Backwards compatible — existing overrides returning true still work (reason shows as "unknown")

Motivation

It's useful to know why a job was interrupted, not just that it was. Currently there's no way to distinguish between max runtime, adapter signal, or custom exit logic without duplicating the checks.

Test plan

  • Existing tests pass (CI)
  • "interrupted.iteration" notification includes reason in payload
  • Log output includes reason= when job is interrupted

🤖 Generated with Claude Code

@SomalianIvan SomalianIvan requested a review from a team as a code owner March 5, 2026 18:17
@SomalianIvan SomalianIvan force-pushed the timb/add-interruption-reason branch 2 times, most recently from 080106b to 3ecf059 Compare March 5, 2026 18:30
`job_should_exit?` now returns a reason string instead of bare `true`:
- "max_job_runtime_exceeded" when runtime limit is hit
- "interrupted" when the interruption adapter signals exit
- Custom overrides can return their own reason strings

The reason is threaded through to the "interrupted.iteration"
ActiveSupport::Notifications event and logged by LogSubscriber.

This is backwards compatible — existing overrides returning `true`
still work (reason shows as "unknown"), and the `reason` key in the
notification payload is additive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SomalianIvan SomalianIvan force-pushed the timb/add-interruption-reason branch from 3ecf059 to a09c0e7 Compare March 5, 2026 19:05
SomalianIvan and others added 2 commits March 5, 2026 14:17
freeze_time prevented any time from elapsing, so the check
`(Time.now.utc - start_time) > 0` was never true with max_job_runtime=0.
Without freeze_time, real time elapses between iterations, triggering
the interruption as expected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Use a slow job class that travels time during each iteration,
matching the pattern used in iteration_test.rb. This avoids
flakiness from relying on real wall time to exceed max_job_runtime.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread lib/job-iteration/iteration.rb Outdated
Comment thread lib/job-iteration/iteration.rb
If the adapter returns a string, use it as the interruption reason.
Otherwise fall back to "interrupted". Also remove unnecessary
|| false from job_should_exit?.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SomalianIvan SomalianIvan requested a review from Mangara March 9, 2026 19:06
@SomalianIvan SomalianIvan force-pushed the timb/add-interruption-reason branch 5 times, most recently from e9f6894 to a18e92d Compare March 10, 2026 15:20
All existing interruption adapters return booleans, so keep it
simple and just use "interrupted" as the reason. Custom adapter
reasons can be added when there's a real need.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@SomalianIvan SomalianIvan force-pushed the timb/add-interruption-reason branch from a18e92d to 3200574 Compare March 10, 2026 15:24

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

Let's add this to the change log, then it's ready.

@SomalianIvan SomalianIvan merged commit 8bf1da7 into main Mar 23, 2026
27 checks passed
@SomalianIvan SomalianIvan deleted the timb/add-interruption-reason branch March 23, 2026 19:47
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.

2 participants