diff --git a/lib/job-iteration/iteration.rb b/lib/job-iteration/iteration.rb index 11edf7bd..d6835209 100644 --- a/lib/job-iteration/iteration.rb +++ b/lib/job-iteration/iteration.rb @@ -40,7 +40,7 @@ def inspected_cursor end end - included do |_base| + included do |base| define_callbacks :start define_callbacks :shutdown define_callbacks :complete @@ -49,10 +49,16 @@ def inspected_cursor :job_iteration_max_job_runtime, instance_writer: false, instance_predicate: false, - default: JobIteration.max_job_runtime, ) - singleton_class.prepend(PrependedClassMethods) + class << base + prepend(PrependedClassMethods) + + def job_iteration_max_job_runtime + # Lookup default every time, instead of closing around its value when the class is defined. + JobIteration.max_job_runtime + end + end end module PrependedClassMethods diff --git a/test/unit/iteration_test.rb b/test/unit/iteration_test.rb index 642b1f8c..85787d88 100644 --- a/test/unit/iteration_test.rb +++ b/test/unit/iteration_test.rb @@ -311,6 +311,17 @@ def test_global_max_job_runtime end end + def test_global_max_job_runtime_with_updated_value + freeze_time + with_global_max_job_runtime(10.minutes) do + klass = build_slow_job_class(iterations: 3, iteration_duration: 30.seconds) + with_global_max_job_runtime(1.minute) do + klass.perform_now + assert_partially_completed_job(cursor_position: 2) + end + end + end + def test_per_class_max_job_runtime_with_default_global freeze_time parent = build_slow_job_class(iterations: 3, iteration_duration: 30.seconds)