Module: JobStatus::TrackedJob

Defined in:
lib/job_status/tracked_job.rb

Overview

Methods to be included within a worker when this module is used with the include keyword

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Setup the callbacks within the worker class

Parameters:

  • base

    base class which will be extended by this module



12
13
14
15
16
17
18
19
20
21
# File 'lib/job_status/tracked_job.rb', line 12

def self.included(base)
  base.extend ClassMethods
  base.class_eval do
    before_enqueue { JobStatus::Tracker.enqueue(@job_id) }

    before_perform { JobStatus::Tracker.update(@job_id, :working ) }

    after_perform { JobStatus::Tracker.update(@job_id, :completed ) }
  end
end

Instance Method Details

#at(job_id, at) ⇒ Object

Store the current position

Parameters:

  • job_id (String)

    ActiveJob job_id to attach information to in storage

  • at (Integer)

    Value to store for the current position



29
30
31
# File 'lib/job_status/tracked_job.rb', line 29

def at(job_id, at)
  storage(job_id, :at, at)
end

#store(job_id, store) ⇒ Object

Store data for the provided job_id

Parameters:

  • job_id (String)

    ActiveJob job_id to attach information to in storage

  • store (Object)

    Data to be save within the storage, can be any serializable object



49
50
51
# File 'lib/job_status/tracked_job.rb', line 49

def store(job_id, store)
  storage(job_id, :store, store)
end

#total(job_id, total) ⇒ Object

Store the the total for the job

Parameters:

  • job_id (String)

    ActiveJob job_id to attach information to in storage

  • total (Integer)

    Value to store for the total positions



39
40
41
# File 'lib/job_status/tracked_job.rb', line 39

def total(job_id, total)
  storage(job_id, :total, total)
end