Class: Pi::Browser::Taskbar::Rails::Broker::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/pi/browser/taskbar/rails/broker.rb

Instance Method Summary collapse

Constructor Details

#initialize(identity:, executable:, task_timeout: 1_800, grace: 300) ⇒ Server

Returns a new instance of Server.



634
635
636
637
638
639
640
641
642
643
644
# File 'lib/pi/browser/taskbar/rails/broker.rb', line 634

def initialize(identity:, executable:, task_timeout: 1_800, grace: 300)
  @identity = identity
  @executable = executable
  @task_timeout = task_timeout
  @grace = grace
  @token = SecureRandom.hex(24)
  @clients = 0
  @clients_mutex = Mutex.new
  @idle_since = nil
  @stopping = false
end

Instance Method Details

#runObject



650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/pi/browser/taskbar/rails/broker.rb', line 650

def run
  owner = false
  File.open(@identity.lock_path, File::RDWR | File::CREAT, 0o600) do |lock|
    return false unless lock.flock(File::LOCK_EX | File::LOCK_NB)
    owner = true
    unlink_if_present(@identity.socket_path)
    @socket = UNIXServer.new(@identity.socket_path)
    File.chmod(0o600, @identity.socket_path)
    @runtime = Runtime.new(project_root: @identity.project_root, executable: @executable, task_timeout: @task_timeout)
    
    accept_loop
  ensure
    if owner
      @socket.close if @socket && !@socket.closed?
      @runtime.close if @runtime
      unlink_if_present(@identity.socket_path)
      unlink_if_present(@identity.)
    end
  end
  true
end

#stopObject



646
647
648
# File 'lib/pi/browser/taskbar/rails/broker.rb', line 646

def stop
  @stopping = true
end