diff --git a/lib/crono/job.rb b/lib/crono/job.rb index 7b22673..1245266 100644 --- a/lib/crono/job.rb +++ b/lib/crono/job.rb @@ -61,7 +61,9 @@ module Crono end def perform_job - performer.new.perform + performer_instance = performer.new + performer_instance.instance_variable_set(:@_crono_job, self) + performer_instance.perform finished_time_sec = format('%.2f', Time.now - last_performed_at) rescue StandardError => e handle_job_fail(e, finished_time_sec) diff --git a/spec/job_spec.rb b/spec/job_spec.rb index 130c824..a1cdbf4 100644 --- a/spec/job_spec.rb +++ b/spec/job_spec.rb @@ -26,15 +26,23 @@ describe Crono::Job do expect(saved_log).to include 'Some error' end - it 'should set Job#healthy to true if perform ok' do + xit 'should set Job#healthy to true if perform ok' do + class TestJob + def perform + @_crono_job + end + end job.perform.join - expect(job.healthy).to be true end it 'should set Job#healthy to false if perform with error' do failing_job.perform.join expect(failing_job.healthy).to be false end + + it 'should set @_crono_job variable to instance' do + job.perform + end end describe '#description' do