Class: QBWC::ActiveRecord::Job
- Inherits:
-
Job
- Object
- Job
- QBWC::ActiveRecord::Job
show all
- Defined in:
- lib/qbwc/active_record/job.rb
Defined Under Namespace
Classes: QbwcJob
Instance Attribute Summary
Attributes inherited from Job
#company, #name, #worker_class
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Job
#disable, #enable, #initialize, #next_request, #pending?, #process_response, #reset, #worker
Constructor Details
This class inherits a constructor from QBWC::Job
Class Method Details
.add_job(name, enabled, company, worker_class, requests, data) ⇒ Object
Creates and persists a job.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/qbwc/active_record/job.rb', line 14
def self.add_job(name, enabled, company, worker_class, requests, data)
worker_class = worker_class.to_s
ar_job = find_ar_job_with_name(name).first_or_initialize
ar_job.company = company
ar_job.enabled = enabled
ar_job.request_index = 0
ar_job.worker_class = worker_class
ar_job.save!
jb = self.new(name, enabled, company, worker_class, requests, data)
jb.requests = requests.is_a?(Array) ? requests : [requests] unless requests.nil?
jb.requests_provided_when_job_added = (! requests.nil? && ! requests.empty?)
jb.data = data
jb
end
|
.clear_jobs ⇒ Object
103
104
105
|
# File 'lib/qbwc/active_record/job.rb', line 103
def self.clear_jobs
QbwcJob.delete_all
end
|
.delete_job_with_name(name) ⇒ Object
46
47
48
49
|
# File 'lib/qbwc/active_record/job.rb', line 46
def self.delete_job_with_name(name)
j = find_ar_job_with_name(name).first
j.destroy unless j.nil?
end
|
.find_ar_job_with_name(name) ⇒ Object
38
39
40
|
# File 'lib/qbwc/active_record/job.rb', line 38
def self.find_ar_job_with_name(name)
QbwcJob.where(:name => name)
end
|
.find_job_with_name(name) ⇒ Object
32
33
34
35
36
|
# File 'lib/qbwc/active_record/job.rb', line 32
def self.find_job_with_name(name)
j = find_ar_job_with_name(name).first
j = j.to_qbwc_job unless j.nil?
return j
end
|
.list_jobs ⇒ Object
99
100
101
|
# File 'lib/qbwc/active_record/job.rb', line 99
def self.list_jobs
QbwcJob.all.map {|ar_job| ar_job.to_qbwc_job}
end
|
.sort_in_time_order(ary) ⇒ Object
107
108
109
|
# File 'lib/qbwc/active_record/job.rb', line 107
def self.sort_in_time_order(ary)
ary.sort {|a,b| a.find_ar_job.first.created_at <=> b.find_ar_job.first.created_at}
end
|
Instance Method Details
#advance_next_request ⇒ Object
94
95
96
97
|
# File 'lib/qbwc/active_record/job.rb', line 94
def advance_next_request
nr = request_index
self.request_index = nr + 1
end
|
#data ⇒ Object
77
78
79
|
# File 'lib/qbwc/active_record/job.rb', line 77
def data
find_ar_job.pluck(:data).first
end
|
#data=(r) ⇒ Object
81
82
83
84
|
# File 'lib/qbwc/active_record/job.rb', line 81
def data=(r)
find_ar_job.update_all(:data => r)
super
end
|
#enabled=(value) ⇒ Object
51
52
53
|
# File 'lib/qbwc/active_record/job.rb', line 51
def enabled=(value)
find_ar_job.update_all(:enabled => value)
end
|
#enabled? ⇒ Boolean
55
56
57
|
# File 'lib/qbwc/active_record/job.rb', line 55
def enabled?
find_ar_job.where(:enabled => true).exists?
end
|
#find_ar_job ⇒ Object
42
43
44
|
# File 'lib/qbwc/active_record/job.rb', line 42
def find_ar_job
self.class.find_ar_job_with_name(name)
end
|
#request_index ⇒ Object
86
87
88
|
# File 'lib/qbwc/active_record/job.rb', line 86
def request_index
find_ar_job.pluck(:request_index).first
end
|
#request_index=(nr) ⇒ Object
90
91
92
|
# File 'lib/qbwc/active_record/job.rb', line 90
def request_index=(nr)
find_ar_job.update_all(:request_index => nr)
end
|
#requests ⇒ Object
59
60
61
|
# File 'lib/qbwc/active_record/job.rb', line 59
def requests
find_ar_job.pluck(:requests).first
end
|
#requests=(r) ⇒ Object
63
64
65
66
|
# File 'lib/qbwc/active_record/job.rb', line 63
def requests=(r)
find_ar_job.update_all(:requests => r)
super
end
|
#requests_provided_when_job_added ⇒ Object
68
69
70
|
# File 'lib/qbwc/active_record/job.rb', line 68
def requests_provided_when_job_added
find_ar_job.pluck(:requests_provided_when_job_added).first
end
|
#requests_provided_when_job_added=(value) ⇒ Object
72
73
74
75
|
# File 'lib/qbwc/active_record/job.rb', line 72
def requests_provided_when_job_added=(value)
find_ar_job.update_all(:requests_provided_when_job_added => value)
super
end
|