Class: Minicron::Transport::Server

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

Overview

Used to mangage the web server minicron runs on

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.serverObject

Returns the value of attribute server


11
12
13
# File 'lib/minicron/transport/server.rb', line 11

def server
  @server
end

Class Method Details

.running?Boolean

Returns a bool based on whether

Returns:

  • (Boolean)

59
60
61
62
63
# File 'lib/minicron/transport/server.rb', line 59

def self.running?
  return false unless !@server.nil?

  @server.running?
end

.start!(host, port, path) ⇒ Object

Starts the thin server

Parameters:

  • host (String)

    the host e.g 0.0.0.0

  • port (Integer)
  • path (String)

    The absolute path to the server e.g /server


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minicron/transport/server.rb', line 19

def self.start!(host, port, path)
  return false if running?

  # Start the faye or rails apps depending on the path
  @server = Thin::Server.new(host, port) do
    use Rack::CommonLogger
    use Rack::ShowExceptions

    # The 'hub', aka our sinatra web interface
    map '/' do
      require Minicron::LIB_PATH + '/minicron/hub/app'
      use Minicron::Hub::ExceptionHandling
      run Minicron::Hub::App.new
    end

    # Set the path faye should start relative to
    faye_path = path == '/' ? '/faye' : "#{path}/faye"

    # The faye server the server and browser clients talk to
    map faye_path do
      require Minicron::LIB_PATH + '/minicron/transport/faye/server'
      run Minicron::Transport::FayeServer.new.server
    end
  end

  @server.start
  true
end

.stop!Boolean

Stops the thin server if it's running

Returns:

  • (Boolean)

    whether the server was stopped or not


50
51
52
53
54
55
# File 'lib/minicron/transport/server.rb', line 50

def self.stop!
  return false unless running? && !@server.nil?

  @server.stop
  true
end