job_boss 0.7.19 → 0.7.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/job_boss.gemspec +1 -1
- data/lib/job_boss/boss.rb +1 -0
- data/lib/job_boss/job.rb +25 -26
- metadata +3 -3
data/job_boss.gemspec
CHANGED
data/lib/job_boss/boss.rb
CHANGED
data/lib/job_boss/job.rb
CHANGED
|
@@ -20,33 +20,32 @@ module JobBoss
|
|
|
20
20
|
|
|
21
21
|
# Method used by the boss to dispatch an employee
|
|
22
22
|
def dispatch(boss)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
value = self.class.call_path(self.path, *self.args)
|
|
35
|
-
|
|
36
|
-
self.update_attribute(:result, value)
|
|
37
|
-
rescue Exception => exception
|
|
38
|
-
mark_exception(exception)
|
|
39
|
-
boss.logger.error "Error running job ##{self.id}!"
|
|
40
|
-
ensure
|
|
41
|
-
until mark_as_completed
|
|
42
|
-
sleep(1)
|
|
43
|
-
end
|
|
23
|
+
boss.logger.info "Dispatching Job ##{self.id}: #{self.prototype}"
|
|
24
|
+
|
|
25
|
+
pid = fork do
|
|
26
|
+
ActiveRecord::Base.connection.reconnect!
|
|
27
|
+
$0 = "[job_boss employee] job ##{self.id} #{self.prototype})"
|
|
28
|
+
Process.setpriority(Process::PRIO_PROCESS, 0, 19)
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
mark_employee
|
|
32
|
+
|
|
33
|
+
value = self.class.call_path(self.path, *self.args)
|
|
44
34
|
|
|
45
|
-
|
|
46
|
-
|
|
35
|
+
self.update_attribute(:result, value)
|
|
36
|
+
rescue Exception => exception
|
|
37
|
+
mark_exception(exception)
|
|
38
|
+
boss.logger.error "Error running job ##{self.id}!"
|
|
39
|
+
ensure
|
|
40
|
+
until mark_as_completed
|
|
41
|
+
sleep(1)
|
|
47
42
|
end
|
|
43
|
+
|
|
44
|
+
boss.logger.info "Job ##{self.id} completed in #{self.time_taken} seconds, exiting..."
|
|
45
|
+
Kernel.exit
|
|
48
46
|
end
|
|
49
47
|
end
|
|
48
|
+
|
|
50
49
|
Process.detach(pid)
|
|
51
50
|
ActiveRecord::Base.connection.reconnect!
|
|
52
51
|
end
|
|
@@ -236,12 +235,12 @@ module JobBoss
|
|
|
236
235
|
end
|
|
237
236
|
end
|
|
238
237
|
|
|
239
|
-
private
|
|
240
|
-
|
|
241
238
|
def mark_as_started
|
|
242
|
-
Job.update_all(['started_at = ?', Time.now], ['started_at IS NULL AND id = ?',
|
|
239
|
+
Job.update_all(['started_at = ?', Time.now], ['started_at IS NULL AND id = ?', self.id]) > 0
|
|
243
240
|
end
|
|
244
241
|
|
|
242
|
+
private
|
|
243
|
+
|
|
245
244
|
def mark_as_cancelled
|
|
246
245
|
update_attributes(:cancelled_at => Time.now)
|
|
247
246
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: job_boss
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 43
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 7
|
|
9
|
-
-
|
|
10
|
-
version: 0.7.
|
|
9
|
+
- 20
|
|
10
|
+
version: 0.7.20
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Brian Underwood
|