job_boss 0.7.18 → 0.7.19

Sign up to get free protection for your applications and to get access to all the features.
data/job_boss.gemspec CHANGED
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "job_boss"
7
- s.version = '0.7.18'
7
+ s.version = '0.7.19'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Brian Underwood"]
10
10
  s.email = ["ml+job_boss@semi-sentient.com"]
data/lib/job_boss/boss.rb CHANGED
@@ -92,8 +92,6 @@ module JobBoss
92
92
 
93
93
  if jobs.empty?
94
94
  jobs = wait_for_jobs
95
- jobs = Job.pending.find(jobs)
96
- Job.update_all(['started_at = ?', Time.now], ['id in (?)', jobs])
97
95
  end
98
96
 
99
97
  [available_employee_count, jobs.size].min.times do
data/lib/job_boss/job.rb CHANGED
@@ -20,30 +20,31 @@ module JobBoss
20
20
 
21
21
  # Method used by the boss to dispatch an employee
22
22
  def dispatch(boss)
23
- mark_as_started
24
- boss.logger.info "Dispatching Job ##{self.id}: #{self.prototype}"
25
-
26
- pid = fork do
27
- ActiveRecord::Base.connection.reconnect!
28
- $0 = "[job_boss employee] job ##{self.id} #{self.prototype})"
29
- Process.setpriority(Process::PRIO_PROCESS, 0, 19)
30
-
31
- begin
32
- mark_employee
33
-
34
- value = self.class.call_path(self.path, *self.args)
23
+ if mark_as_started
24
+ boss.logger.info "Dispatching Job ##{self.id}: #{self.prototype}"
25
+
26
+ pid = fork do
27
+ ActiveRecord::Base.connection.reconnect!
28
+ $0 = "[job_boss employee] job ##{self.id} #{self.prototype})"
29
+ Process.setpriority(Process::PRIO_PROCESS, 0, 19)
30
+
31
+ begin
32
+ mark_employee
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
35
44
 
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)
45
+ boss.logger.info "Job ##{self.id} completed in #{self.time_taken} seconds, exiting..."
46
+ Kernel.exit
43
47
  end
44
-
45
- boss.logger.info "Job ##{self.id} completed in #{self.time_taken} seconds, exiting..."
46
- Kernel.exit
47
48
  end
48
49
  end
49
50
  Process.detach(pid)
@@ -238,7 +239,7 @@ module JobBoss
238
239
  private
239
240
 
240
241
  def mark_as_started
241
- update_attributes(:started_at => Time.now)
242
+ Job.update_all(['started_at = ?', Time.now], ['started_at IS NULL AND id = ?', job]) > 0
242
243
  end
243
244
 
244
245
  def mark_as_cancelled
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: 39
4
+ hash: 37
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 18
10
- version: 0.7.18
9
+ - 19
10
+ version: 0.7.19
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Underwood