Class: CukeCIWorkers::Runner

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

Instance Attribute Summary

Attributes inherited from Worker

#logger

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/cuke_ci_workers/runner.rb', line 15

def initialize(options)
  @configuration_file_name = options[:configuration_file_name]
  @configuration = YAML.load_file(@configuration_file_name)
  
  @poll_uri = URI.parse(@configuration['poll_url'])
  @push_url = @configuration['push_url']

  @verbose = options[:verbose]
  
  super(@configuration['log_file_name'], @configuration['log_level'])
end

Class Method Details

.parse!(args) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/cuke_ci_workers/runner.rb', line 144

def parse!(args)
  default_runner_config_file_name = './cuke_ci_runner_config.yml'
  options = {}
  
  opts = OptionParser.new do |opts|
    opts.banner = 'Usage: ...'

    opts.on("-c", "--configuration CONFIGURATION_FILE_NAME", "Path to configuration file. Defaults to '#{default_runner_config_file_name}'.") do |file_name|
      options[:configuration_file_name] = file_name
    end

    opts.on("-v", "--verbose", "Be verbose") do |v|
      options[:verbose] = true
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end
  opts.parse!

  options[:configuration_file_name] ||= default_runner_config_file_name

  begin
    self.new(options)
  rescue 
    puts "Could not open configuration file at '#{options[:configuration_file_name]}'."
    exit
  end
rescue OptionParser::ParseError
  puts opts
  exit
end

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cuke_ci_workers/runner.rb', line 27

def run
  $running = true

  Signal.trap('INT') {
    say('Exiting...')
    $running = false
  }

  while($running) do
    begin
      run_present = poll_for_run
    rescue Exception => e
      log_exception(e)
    end
    
    if run_present
      say('Found run.')
      
      begin
        pull_repo
        checkout_commit
        prepare
        
        if result = cucumber
          push_result(result)
        else
          push_error
        end
      rescue Exception => e
        log_exception(e)
      end
    else
      say('Nothing found. Going to sleep...')
      sleep 5
    end
  end
end