Class: PeriodicJob::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/periodic_job_mongoid/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval, job_id, block, error_handler, before, after) ⇒ Job

Returns a new instance of Job.



13
14
15
16
17
18
19
20
21
# File 'lib/periodic_job_mongoid/job.rb', line 13

def initialize(interval, job_id, block, error_handler, before, after)
  @interval = interval
  @job_id = job_id
  @block = block
  @error_handler = error_handler
  @before = before
  @after = after
  schedule
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



11
12
13
# File 'lib/periodic_job_mongoid/job.rb', line 11

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



10
11
12
# File 'lib/periodic_job_mongoid/job.rb', line 10

def before
  @before
end

#blockObject (readonly)

Returns the value of attribute block.



7
8
9
# File 'lib/periodic_job_mongoid/job.rb', line 7

def block
  @block
end

#error_handlerObject (readonly)

Returns the value of attribute error_handler.



9
10
11
# File 'lib/periodic_job_mongoid/job.rb', line 9

def error_handler
  @error_handler
end

#intervalObject (readonly)

Returns the value of attribute interval.



5
6
7
# File 'lib/periodic_job_mongoid/job.rb', line 5

def interval
  @interval
end

#job_idObject (readonly)

Returns the value of attribute job_id.



6
7
8
# File 'lib/periodic_job_mongoid/job.rb', line 6

def job_id
  @job_id
end

#run_afterObject (readonly)

Returns the value of attribute run_after.



8
9
10
# File 'lib/periodic_job_mongoid/job.rb', line 8

def run_after
  @run_after
end

Instance Method Details

#checkpointObject



23
24
25
# File 'lib/periodic_job_mongoid/job.rb', line 23

def checkpoint
  Checkpoint[@job_id]
end

#tickObject



27
28
29
30
31
32
# File 'lib/periodic_job_mongoid/job.rb', line 27

def tick
  if checkpoint.advance_if_older_than @run_after
    run
    schedule
  end
end