@@ -150,44 +150,14 @@ def delete_completed_job(job_id, params)
150150 JSON . parse ( last_response . body )
151151 end
152152
153- def asynchronously ( options = { start_worker : false } )
153+ def asynchronously ( _options = { start_worker : false } )
154154 old_config_solve_synchronously = OptimizerWrapper . config [ :solve ] [ :synchronously ]
155155 OptimizerWrapper . config [ :solve ] [ :synchronously ] = false
156156 old_resque_inline = Resque . inline
157157 Resque . inline = false
158- if options [ :start_worker ] && !ENV [ 'DOCKER' ]
159- pid_worker = Process . spawn ( { 'COUNT' => '1' , 'QUEUE' => 'DEFAULT' } ,
160- 'bundle exec rake resque:workers --trace' , pgroup : true ) # don't create another shell
161- pgid_worker = Process . getpgid ( pid_worker )
162- while `ps -o pgid | grep #{ pgid_worker } ` . split ( /\n / ) . size < 2
163- puts "#{ Time . now } Waiting for the worker to launch"
164- sleep 0.1
165- end
166- puts "#{ Time . now } Worker is started"
167- sleep 0.1
168- end
169158 yield
170159 ensure
171160 Resque . inline = old_resque_inline
172161 OptimizerWrapper . config [ :solve ] [ :synchronously ] = old_config_solve_synchronously
173- if options [ :start_worker ] && !ENV [ 'DOCKER' ] && pgid_worker
174- # Kill all grandchildren
175- worker_pids = `ps -o pgid,pid | grep #{ pgid_worker } ` . split ( /\n / )
176- worker_pids . collect! { |i | i . split ( ' ' ) [ -1 ] . to_i }
177- worker_pids . sort!
178- worker_pids . reverse_each { |pid |
179- next if pid == pgid_worker
180-
181- Process . kill ( 'SIGKILL' , pid )
182- Process . detach ( pid )
183- }
184- Process . kill ( 'SIGTERM' , -pgid_worker ) # Kill the process group (this doesn't kill grandchildren)
185- Process . waitpid ( -pgid_worker , 0 )
186- while `ps -o pgid,pid | grep "#{ worker_pids . join ( '\|' ) } "` . split ( /\n / ) . any?
187- puts "#{ Time . now } Waiting the worker process group #{ pgid_worker } to die\n "
188- sleep 0.1
189- end
190- puts "#{ Time . now } Worker is killed"
191- end
192162 end
193163end
0 commit comments