Class: Nitra::Tasks

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Tasks

Returns a new instance of Tasks.



4
5
6
7
8
9
10
# File 'lib/nitra/tasks.rb', line 4

def initialize(runner)
  @runner = runner
  if runner.configuration.rake_tasks.keys.any?
    require 'rake'
    Rake.load_rakefile("Rakefile")
  end
end

Instance Attribute Details

#runnerObject (readonly)

Returns the value of attribute runner.



2
3
4
# File 'lib/nitra/tasks.rb', line 2

def runner
  @runner
end

Instance Method Details

#run(name, count = 1) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nitra/tasks.rb', line 12

def run(name, count = 1)
  return unless tasks = runner.configuration.rake_tasks[name]
  runner.debug "Running #{name} tasks: #{tasks.inspect}"
  rd, wr = IO.pipe
  (1..count).collect do |index|
    fork do
      ENV["TEST_ENV_NUMBER"] = index.to_s
      rd.close
      $stdout.reopen(wr)
      $stderr.reopen(wr)
      connect_to_database
      Array(tasks).each do |task|
        Rake::Task[task].invoke
      end
    end
  end
  wr.close
  output = ""
  loop do
    IO.select([rd])
    text = rd.read
    break if text.nil? || text.length.zero?
    output.concat text
  end
  rd.close
  successful = all_children_successful?
  runner.server_channel.write("command" => (successful ? 'stdout' : 'error'), "process" => tasks.inspect, "text" => output)
  exit if !successful
end