hive-runner 2.1.26 → 2.1.27

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hive/device.rb +22 -15
  3. data/lib/hive/worker.rb +16 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad70ec960f421f7fe4345b0e38009b4bdcb9a0e9
4
- data.tar.gz: b4b58e12fbd9b3e779c82c8f17e5389253efdd3d
3
+ metadata.gz: b3302ae2a64590d9f205a92748ab4dd15168af0f
4
+ data.tar.gz: 3bde86d13078501ca242ca19ae155cdf587145c6
5
5
  SHA512:
6
- metadata.gz: 85a57f836dfd1ef46bfa80ead6f5bcbf8bffe10adbada4c5f5c9ab556d22ead8ae231f69c8396b0c89cfaaec5ff1fa07ffd6d9cd64a35d1a38d4b752bff4e37f
7
- data.tar.gz: 387013f1b155ff46cedf66144dbd3fc70718dba5559ddc8e6a21a5b930b4783a7aea5958d3a752c1f1d37391b53ea27cfa656ec7b83fe1d662a612e486d88071
6
+ metadata.gz: 06537e131a338ad1688c5ce7f98b67f6876222a2dcab417e2d071f58a99b726c0704a32415eeba8f17467b917284f8f8e14dfc69a8fda770f77a7a02f825fa58
7
+ data.tar.gz: cd8d1db47eb7bdcf61aa8d8ea8ee524f527427e1a72abfce90f76413b8044618a67ff70bd0596cc292f9b3e1114105deba1c7aa82ed16684be33ce8e105f6ce6
@@ -34,24 +34,31 @@ module Hive
34
34
 
35
35
  # Terminate the worker process
36
36
  def stop
37
- @stop_count = @stop_count.nil? ? 0 : @stop_count + 1
37
+ protect_file = File.expand_path("#{@worker_pid}.protect", PIDS_DIRECTORY)
38
+ Hive.logger.debug("Checking for protected file: #{protect_file}")
39
+ if File.exists? File.expand_path("#{@worker_pid}.protect", PIDS_DIRECTORY)
40
+ Hive.logger.debug("PID #{@worker_pid} is protected")
41
+ false
42
+ else
43
+ @stop_count = @stop_count.nil? ? 0 : @stop_count + 1
38
44
 
39
- if self.running?
40
- if @stop_count < 30
41
- Hive.logger.info("Attempting to terminate process #{@worker_pid} [#{@stop_count}]")
42
- Process.kill 'TERM', @worker_pid
43
- else
44
- Hive.logger.info("Killing process #{@worker_pid}")
45
- Process.kill 'KILL', @worker_pid if self.running?
45
+ if self.running?
46
+ if @stop_count < 30
47
+ Hive.logger.info("Attempting to terminate process #{@worker_pid} [#{@stop_count}]")
48
+ Process.kill 'TERM', @worker_pid
49
+ else
50
+ Hive.logger.info("Killing process #{@worker_pid}")
51
+ Process.kill 'KILL', @worker_pid if self.running?
52
+ end
46
53
  end
47
- end
48
54
 
49
- if self.running?
50
- false
51
- else
52
- @worker_pid = nil
53
- @stop_count = nil
54
- true
55
+ if self.running?
56
+ false
57
+ else
58
+ @worker_pid = nil
59
+ @stop_count = nil
60
+ true
61
+ end
55
62
  end
56
63
  end
57
64
 
@@ -8,6 +8,7 @@ require 'hive/messages'
8
8
  require 'hive/port_allocator'
9
9
  require 'code_cache'
10
10
  require 'res'
11
+ require 'fileutils'
11
12
 
12
13
  module Hive
13
14
  # The generic worker class
@@ -249,7 +250,9 @@ module Hive
249
250
  # Diagnostics function to be extended in child class, as required
250
251
  def diagnostics
251
252
  retn = true
253
+ protect
252
254
  retn = @diagnostic_runner.run if !@diagnostic_runner.nil?
255
+ unprotect
253
256
  @log.info('Diagnostics failed') if not retn
254
257
  status = device_status
255
258
  status = set_device_status('happy') if status == 'busy'
@@ -500,5 +503,18 @@ module Hive
500
503
  def hive_mind_device_identifiers
501
504
  { id: @device_id }
502
505
  end
506
+
507
+ private
508
+ def protect
509
+ @protect_file = File.expand_path("#{Process.pid}.protect", PIDS_DIRECTORY)
510
+ @log.debug("Protecting worker with #{@protect_file}")
511
+ FileUtils.touch @protect_file
512
+ end
513
+
514
+ def unprotect
515
+ @log.debug("Unprotecting worker with #{@protect_file}")
516
+ File.unlink @protect_file if @protect_file
517
+ @protect_file = nil
518
+ end
503
519
  end
504
520
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.26
4
+ version: 2.1.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Haig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chamber