Module: Fasten::Support::ThreadWorker
- Defined in:
- lib/fasten/support/thread_worker.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #kill ⇒ Object
- #receive_request_from_parent ⇒ Object
- #redirect_std(path) ⇒ Object
- #restore_std ⇒ Object
- #send_request_to_child(task) ⇒ Object
- #send_response_to_parent(task) ⇒ Object
- #start ⇒ Object
Instance Attribute Details
#thread ⇒ Object
Returns the value of attribute thread.
6 7 8 |
# File 'lib/fasten/support/thread_worker.rb', line 6 def thread @thread end |
Instance Method Details
#kill ⇒ Object
16 17 18 19 20 21 22 23 |
# 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 ⇒ Object
34 35 36 |
# File 'lib/fasten/support/thread_worker.rb', line 34 def receive_request_from_parent @queue.pop end |
#redirect_std(path) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# 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 ⇒ Object
54 55 56 57 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 |
# 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) ⇒ Object
38 39 40 41 42 |
# 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 ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/fasten/support/thread_worker.rb', line 8 def start @queue = Queue.new self.thread = Thread.new do process_incoming_requests end end |