Class: Nitra::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/nitra/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration, server_channel, runner_id) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nitra/runner.rb', line 6

def initialize(configuration, server_channel, runner_id)
  ENV["RAILS_ENV"] = configuration.environment

  @workers         = {}
  @runner_id       = runner_id
  @framework       = configuration.framework
  @configuration   = configuration
  @server_channel  = server_channel
  @tasks           = Nitra::Tasks.new(self)

  configuration.calculate_default_process_count
  server_channel.raise_epipe_on_write_error = true
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def configuration
  @configuration
end

#frameworkObject (readonly)

Returns the value of attribute framework.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def framework
  @framework
end

#runner_idObject (readonly)

Returns the value of attribute runner_id.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def runner_id
  @runner_id
end

#server_channelObject (readonly)

Returns the value of attribute server_channel.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def server_channel
  @server_channel
end

#tasksObject (readonly)

Returns the value of attribute tasks.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def tasks
  @tasks
end

#workersObject (readonly)

Returns the value of attribute workers.



4
5
6
# File 'lib/nitra/runner.rb', line 4

def workers
  @workers
end

Instance Method Details

#debug(*text) ⇒ Object



41
42
43
44
45
# File 'lib/nitra/runner.rb', line 41

def debug(*text)
  if configuration.debug
    server_channel.write("command" => "debug", "text" => "runner #{runner_id}: #{text.join}")
  end
end

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nitra/runner.rb', line 20

def run
  tasks.run(:before_runner)

  load_rails_environment

  tasks.run(:before_worker, configuration.process_count)

  start_workers

  trap("SIGTERM") { $aborted = true }
  trap("SIGINT") { $aborted = true }

  hand_out_files_to_workers

  tasks.run(:after_runner)
rescue Errno::EPIPE
ensure
  trap("SIGTERM", "DEFAULT")
  trap("SIGINT", "DEFAULT")
end