Class: Workarea::Scheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/workarea/scheduler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Scheduler

Returns a new instance of Scheduler.



15
16
17
18
19
20
# File 'lib/workarea/scheduler.rb', line 15

def initialize(options = {})
  @time = options[:at]
  @worker = options[:worker]
  @args = options[:args]
  @job_id = options[:job_id]
end

Instance Attribute Details

#job_idObject (readonly)

Returns the value of attribute job_id.



3
4
5
# File 'lib/workarea/scheduler.rb', line 3

def job_id
  @job_id
end

Class Method Details

.delete(job_id) ⇒ Object



11
12
13
# File 'lib/workarea/scheduler.rb', line 11

def self.delete(job_id)
  new(job_id: job_id).delete
end

.schedule(*args) ⇒ Object



5
6
7
8
9
# File 'lib/workarea/scheduler.rb', line 5

def self.schedule(*args)
  instance = new(*args)
  instance.perform
  instance.job_id
end

Instance Method Details

#add_jobObject



31
32
33
# File 'lib/workarea/scheduler.rb', line 31

def add_job
  @job_id = @worker.perform_at(@time, *@args)
end

#deleteObject



27
28
29
# File 'lib/workarea/scheduler.rb', line 27

def delete
  current_job.try(:delete)
end

#performObject



22
23
24
25
# File 'lib/workarea/scheduler.rb', line 22

def perform
  delete
  add_job
end