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.



6
7
8
9
# File 'lib/crabfarm/crabtrap_runner.rb', line 6

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

Instance Method Details

#is_running?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/crabfarm/crabtrap_runner.rb', line 11

def is_running?
  not @pid.nil?
end

#modeObject



19
20
21
# File 'lib/crabfarm/crabtrap_runner.rb', line 19

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

#portObject



15
16
17
# File 'lib/crabfarm/crabtrap_runner.rb', line 15

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

#startObject



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

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



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

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