job_boss 0.7.19 → 0.7.20

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.19'
7
+ s.version = '0.7.20'
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,6 +92,7 @@ module JobBoss
92
92
 
93
93
  if jobs.empty?
94
94
  jobs = wait_for_jobs
95
+ jobs = jobs.to_a.select(&:mark_as_started)
95
96
  end
96
97
 
97
98
  [available_employee_count, jobs.size].min.times do
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
- 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
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
- boss.logger.info "Job ##{self.id} completed in #{self.time_taken} seconds, exiting..."
46
- Kernel.exit
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 = ?', job]) > 0
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: 37
4
+ hash: 43
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 19
10
- version: 0.7.19
9
+ - 20
10
+ version: 0.7.20
11
11
  platform: ruby
12
12
  authors:
13
13
  - Brian Underwood