Class: Raque::Runner

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

Class Method Summary collapse

Class Method Details

.capture_stdoutObject



30
31
32
33
34
35
36
37
38
# File 'lib/raque/runner.rb', line 30

def self.capture_stdout
  s = StringIO.new
  oldstdout = $stdout
  $stdout = s
  yield
  s.string
ensure
  $stdout = oldstdout
end

.perform(task_string, output_file = false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/raque/runner.rb', line 8

def self.perform task_string, output_file = false
  logger = Logger.new(output_file || STDOUT)

  logger.info "[Raque] Received task string \"#{task_string}\""
  args = []
  if args_s = task_string.match(/\[.*\]/)
    args = eval args_s.to_s
    task_string.gsub! /\[.*\]/, ''
  end

  logger.info "[Raque] Starting Rake task \"#{task_string}\""
  logger.info "[Raque] with arguments #{args.inspect}" if args.size > 0

  result = capture_stdout { Rake::Task[task_string].invoke *args }

  Rake::Task[task_string].reenable

  logger.info result
  logger.info "[Raque] Finished Rake task\n"
  logger.close
end