Class: JobWrapper

Inherits:
Object
  • Object
show all
Defined in:
app/models/job_wrapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(delayed_job) ⇒ JobWrapper

Returns a new instance of JobWrapper.


3
4
5
6
7
# File 'app/models/job_wrapper.rb', line 3

def initialize(delayed_job)
  @uuid = extract_uuid_from_handler_string(delayed_job.handler)
  @job_type = extract_job_type_from_handler_string(delayed_job.handler)
  @delayed_job = delayed_job
end

Class Method Details

.allObject


9
10
11
12
13
14
15
# File 'app/models/job_wrapper.rb', line 9

def self.all
  list = []
  Delayed::Web::Job.all.each do |delayed_job|
    list << JobWrapper.new(delayed_job)
  end
  list
end

.find(id) ⇒ Object


17
18
19
# File 'app/models/job_wrapper.rb', line 17

def self.find(id)
  JobWrapper.new(Delayed::Web::Job.find(id))
end

.find_by_uuid(uuid) ⇒ Object


21
22
23
24
25
26
27
28
# File 'app/models/job_wrapper.rb', line 21

def self.find_by_uuid(uuid)
  self.all.each do |job|
    if job.uuid == uuid
      return job
    end
  end
  return NIL
end

Instance Method Details

#extract_job_type_from_handler_string(handlerstring) ⇒ Object (private)


46
47
48
49
50
# File 'app/models/job_wrapper.rb', line 46

def extract_job_type_from_handler_string(handlerstring)
  startindex = handlerstring.index('job_class:') + 10
  endindex = handlerstring.index('job_id:') - 4
  handlerstring.at(startindex..endindex)
end

#extract_uuid_from_handler_string(handlerstring) ⇒ Object (private)


41
42
43
44
# File 'app/models/job_wrapper.rb', line 41

def extract_uuid_from_handler_string(handlerstring)
  startindex = handlerstring.index('job_id:')
  handlerstring[startindex + 8,36]
end

#job_typeObject


34
35
36
# File 'app/models/job_wrapper.rb', line 34

def job_type
  @job_type
end

#uuidObject


30
31
32
# File 'app/models/job_wrapper.rb', line 30

def uuid
  @uuid
end