Class: MongoJob::Job
- Inherits:
-
Object
- Object
- MongoJob::Job
- Defined in:
- lib/mongojob/job.rb
Overview
You should extend this class to handle jobs
Instance Attribute Summary collapse
-
#log ⇒ Object
Returns the value of attribute log.
Class Method Summary collapse
Instance Method Summary collapse
-
#at(*args) ⇒ Object
Set the status of the job for the current itteration.
- #id ⇒ Object
-
#initialize(job_object, logger = nil) ⇒ Job
constructor
A new instance of Job.
- #options ⇒ Object
-
#perform ⇒ Object
Please implement this method to perform any actual work.
-
#update_status(status) ⇒ Object
Set custom status for the job.
Constructor Details
#initialize(job_object, logger = nil) ⇒ Job
Returns a new instance of Job.
21 22 23 24 |
# File 'lib/mongojob/job.rb', line 21 def initialize(job_object, logger = nil) @job = job_object @log = logger || Logger.new(STDOUT) end |
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
5 6 7 |
# File 'lib/mongojob/job.rb', line 5 def log @log end |
Class Method Details
.fiber? ⇒ Boolean
13 14 15 |
# File 'lib/mongojob/job.rb', line 13 def self.fiber? @threading == :fiber end |
.fork? ⇒ Boolean
10 11 12 |
# File 'lib/mongojob/job.rb', line 10 def self.fork? @threading == :fork end |
.queue(queue = nil) ⇒ Object
17 18 19 |
# File 'lib/mongojob/job.rb', line 17 def self.queue(queue = nil) @queue ||= queue end |
.threading(threading) ⇒ Object
7 8 9 |
# File 'lib/mongojob/job.rb', line 7 def self.threading threading @threading = threading end |
Instance Method Details
#at(*args) ⇒ Object
Set the status of the job for the current itteration. num
and total
are passed to the status as well as any messages.
Usage: at(0.29) - at 29% at(0.29,1.0) - at 29% at(29,100) - at 29% at(2,7) - at 2 of 7 at(2,7, {foo: ‘bar’}) - at 2 of 7, and set custom_status
50 51 52 |
# File 'lib/mongojob/job.rb', line 50 def at *args @job.at *args end |
#id ⇒ Object
30 31 32 |
# File 'lib/mongojob/job.rb', line 30 def id @job.id end |
#options ⇒ Object
26 27 28 |
# File 'lib/mongojob/job.rb', line 26 def @job. end |
#perform ⇒ Object
Please implement this method to perform any actual work.
35 36 37 |
# File 'lib/mongojob/job.rb', line 35 def perform end |
#update_status(status) ⇒ Object
Set custom status for the job. Accepts a hash as a parameter.
55 56 57 58 59 60 |
# File 'lib/mongojob/job.rb', line 55 def update_status status @job.set({ custom_status: status, pinged_at: Time.now }) end |