Class: Docscribe::Server::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/docscribe/server.rb

Overview

Daemon process that loads the Ruby runtime once and serves requests.

Instance Method Summary collapse

Constructor Details

#initialize(socket_path: nil, idle_timeout: IDLE_TIMEOUT, config_path: nil) ⇒ void

Parameters:

  • socket_path (String?) (defaults to: nil)

    custom socket path

  • idle_timeout (Integer) (defaults to: IDLE_TIMEOUT)

    seconds before automatic shutdown

  • config_path (String?) (defaults to: nil)

    custom config path



339
340
341
342
343
344
345
346
347
348
# File 'lib/docscribe/server.rb', line 339

def initialize(socket_path: nil, idle_timeout: IDLE_TIMEOUT, config_path: nil)
  @socket_path = socket_path || Server.socket_path(config_path)
  @idle_timeout = idle_timeout
  @config_path = config_path
  @last_request_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  @running = false
  @server = nil
  @file_cache = LRUCache.new
  @started_at = Time.now
end

Instance Method Details

#startvoid

This method returns an undefined value.

Start the daemon: load dependencies, bind socket, enter listen loop.



353
354
355
356
357
358
359
360
# File 'lib/docscribe/server.rb', line 353

def start
  load_dependencies
  setup_socket
  @running = true
  $PROGRAM_NAME = "docscribe server (#{Dir.pwd})"
  write_pid
  listen_loop
end