module Fasten::Support::ThreadWorker
Attributes
thread[RW]
Public Instance Methods
kill()
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 16 def kill log_info 'Removing worker' thread.exit rescue StandardError => e log_warn "Ignoring error killing worker #{self}, error: #{e}" ensure @queue.clear end
receive_request_from_parent()
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 34 def receive_request_from_parent @queue.pop end
redirect_std(path)
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 44 def redirect_std(path) StdThreadProxy.install FileUtils.mkdir_p File.dirname(path) @redirect_log = File.new path, 'a' @redirect_log.sync = true StdThreadProxy.thread_io = @redirect_log logger.reopen(@redirect_log) end
restore_std()
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 54 def restore_std @redirect_log&.close StdThreadProxy.thread_io = nil end
send_request_to_child(task)
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 25 def send_request_to_child(task) task.state = :RUNNING task.worker = self self.running_task = task self.state = :RUNNING @queue.push task end
send_response_to_parent(task)
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 38 def send_response_to_parent(task) log_info "Sending task response back to runner #{task}" runner.queue.push task end
start()
click to toggle source
# File lib/fasten/support/thread_worker.rb, line 8 def start @queue = Queue.new self.thread = Thread.new do process_incoming_requests end end