Class: Crabfarm::CrabtrapRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/crabfarm/crabtrap_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(_config = {}) ⇒ CrabtrapRunner

Returns a new instance of CrabtrapRunner.



4
5
6
7
# File 'lib/crabfarm/crabtrap_runner.rb', line 4

def initialize(_config={})
  @config = _config;
  @pid = nil
end

Instance Method Details

#is_running?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/crabfarm/crabtrap_runner.rb', line 9

def is_running?
  not @pid.nil?
end

#modeObject



17
18
19
# File 'lib/crabfarm/crabtrap_runner.rb', line 17

def mode
  @config.fetch(:mode, :pass).to_sym
end

#portObject



13
14
15
# File 'lib/crabfarm/crabtrap_runner.rb', line 13

def port
  @config[:port] # TODO: maybe select port dynamically...
end

#startObject



21
22
23
24
25
26
27
28
29
# File 'lib/crabfarm/crabtrap_runner.rb', line 21

def start
  begin
    @pid = Process.spawn({}, crabtrap_cmd)
    wait_for_server
  rescue
    puts "Could not find crabtrap at #{@config[:bin_path]}, memento replaying is disabled!"
    @pid = nil
  end
end

#stopObject



31
32
33
34
35
36
37
# File 'lib/crabfarm/crabtrap_runner.rb', line 31

def stop
  unless @pid.nil?
    Process.kill("INT", @pid)
    Process.wait @pid
    @pid = nil
  end
end