process_controller 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c500f9338466a353da79e0b1e9474924ebb47952
4
- data.tar.gz: 0c709ceb07406b33e958166871449e8caeb44cff
3
+ metadata.gz: d4f8282d1b6740eda4a080f6c131349a2fc38cd7
4
+ data.tar.gz: d616f99ae1d8f0734b80809bf38ee370e6ebe45f
5
5
  SHA512:
6
- metadata.gz: 1d0aa3e759821bcf3eb63db5f181d5d7a395b58c59064552d2045419680fa575fe64eecac63fdf685b86cfbc2068907eeaefaa25a42d54e73830b029a617f1eb
7
- data.tar.gz: 4be27cb4761086a65b0325caacc653852e029657756df52083fb5d17f8f20c1f46984e06f12d3d921bcefcdf76b9e0bca0a7dc801ac6a11d7fc08bc92bb767de
6
+ metadata.gz: 13a6be95655ec1d751c95b68dfe58edbc04e19f5243a675bc2c4e21d0bdf56eb0a10e321bd9971ff774d9a9f47ca19b37b2c5d9554c3f0ec8ec4c03a5ff84489
7
+ data.tar.gz: 11419c027bd14c442a3741f426626dc068977df5d6211bb8a4e1bbbe1a3d6ce8909085d991cd0a1e1490eddde394ac29bc2ce48a31a945ca6314528514f13941
@@ -1,3 +1,3 @@
1
1
  module Control
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
@@ -23,6 +23,7 @@ module ControlHelper
23
23
  end
24
24
 
25
25
  def get_pid_from_file(pid_filename)
26
+ return nil unless File.exists?(pid_filename)
26
27
  File.open(pid_filename, &:readline).strip
27
28
  end
28
29
 
@@ -95,9 +96,21 @@ module ControlHelper
95
96
  p "error in killing process #{e.inspect}"
96
97
  end
97
98
 
99
+ # Note , only valid for http servers
98
100
  def restart_the_app!(options)
99
- restart_command = options.fetch(Control_P::OPTIONS_ATTRIBUTES[:restart_command])
100
- `#{restart_command}`
101
+ if app_not_running?(options)
102
+ start_a_new_process!(options)
103
+ else
104
+ restart_command = options.fetch(Control_P::OPTIONS_ATTRIBUTES[:restart_command])
105
+ `#{restart_command}`
106
+ sleep(5)
107
+ end
108
+ end
109
+
110
+ def app_not_running?(options)
111
+ pid_filename = options.fetch(Control_P::OPTIONS_ATTRIBUTES[:pid_filename], nil)
112
+ raise "no pid filename found in #{options}" if pid_filename.nil?
113
+ '' == `cat #{pid_filename}`
101
114
  end
102
115
 
103
116
  def kill_with_retries!(options)
@@ -134,16 +147,17 @@ module ControlHelper
134
147
 
135
148
  #TODO add option to overwrite the file names
136
149
  def print_workers_started_and_stopped(options)
137
- print_file('workers_started', Control_P::WORKERS_STARTED_EXTENTION)
138
- print_file('workers_closed', Control_P::WORKERS_CLOSED_EXTENTION)
150
+ print_workers_and_delete_files!('workers started', Control_P::WORKERS_STARTED_EXTENTION)
151
+ print_workers_and_delete_files!('workers closed', Control_P::WORKERS_CLOSED_EXTENTION)
139
152
  end
140
153
 
141
- def print_file(type, file_name)
142
- p type + Dir["*.closed"].length
154
+ def print_workers_and_delete_files!(type, extention)
155
+ p "#{Dir[extention].length.to_s} #{type}"
156
+ Dir.glob(extention).each { |f| File.delete(f) }
143
157
  end
144
158
 
145
159
  def http_server?(options)
146
- true == options.fetch(OPTIONS_ATTRIBUTES[:http_server], false)
160
+ true == options.fetch(Control_P::OPTIONS_ATTRIBUTES[:http_server], false)
147
161
  end
148
162
 
149
163
  def kill_the_old_process_if_needed(options)
@@ -10,8 +10,8 @@ class Control_P
10
10
  start_command: 'start_command'}.with_indifferent_access
11
11
 
12
12
  FIND_BY_OPTIONS = {app_filename: 'app_filename', port_num: 'port_num', app_name: 'app_name', pid_file: 'pid_file'}.with_indifferent_access
13
- WORKERS_STARTED_EXTENTION = 'started'
14
- WORKERS_CLOSED_EXTENTION = 'closed'
13
+ WORKERS_STARTED_EXTENTION = '*.started'
14
+ WORKERS_CLOSED_EXTENTION = '*.closed'
15
15
 
16
16
  HOSTNAME = Socket.gethostname
17
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - ohad partuck