Module: Jobba::RecordStatus

Included in:
Hippo::Job
Defined in:
lib/hippo/job.rb

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/hippo/job.rb', line 8

def self.included(klass)
    klass.send(:attr_reader, :job_status)
    klass.around_enqueue do |job, block|
        @job_status = Jobba.find!(job.job_id)
        @job_status.set_job_name(self.class.to_s)
        @job_status.unqueued!
        block.call
        @job_status.queued!
    end
    klass.around_perform do |job, block|
        # we use find! so it will create a record of the job even if
        # it's created using perform_now.  In that case the enqueue step's skipped
        @job_status = Jobba.find!(job.job_id)
        @job_status.started!
        block.call
        @job_status.succeeded!
    end
end