Class: Specbandit::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/specbandit/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Specbandit.configuration.key, batch_size: Specbandit.configuration.batch_size, rspec_opts: Specbandit.configuration.rspec_opts, key_rerun: Specbandit.configuration.key_rerun, key_rerun_ttl: Specbandit.configuration.key_rerun_ttl, queue: nil, output: $stdout) ⇒ Worker

Returns a new instance of Worker.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/specbandit/worker.rb', line 10

def initialize(
  key: Specbandit.configuration.key,
  batch_size: Specbandit.configuration.batch_size,
  rspec_opts: Specbandit.configuration.rspec_opts,
  key_rerun: Specbandit.configuration.key_rerun,
  key_rerun_ttl: Specbandit.configuration.key_rerun_ttl,
  queue: nil,
  output: $stdout
)
  @key = key
  @batch_size = batch_size
  @rspec_opts = Array(rspec_opts)
  @key_rerun = key_rerun
  @key_rerun_ttl = key_rerun_ttl
  @queue = queue || RedisQueue.new
  @output = output
end

Instance Attribute Details

#batch_sizeObject (readonly)

Returns the value of attribute batch_size.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def batch_size
  @batch_size
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def key
  @key
end

#key_rerunObject (readonly)

Returns the value of attribute key_rerun.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def key_rerun
  @key_rerun
end

#key_rerun_ttlObject (readonly)

Returns the value of attribute key_rerun_ttl.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def key_rerun_ttl
  @key_rerun_ttl
end

#outputObject (readonly)

Returns the value of attribute output.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def output
  @output
end

#queueObject (readonly)

Returns the value of attribute queue.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def queue
  @queue
end

#rspec_optsObject (readonly)

Returns the value of attribute rspec_opts.



8
9
10
# File 'lib/specbandit/worker.rb', line 8

def rspec_opts
  @rspec_opts
end

Instance Method Details

#runObject

Main entry point. Detects the operating mode and dispatches accordingly.

Returns 0 if all batches passed (or nothing to do), 1 if any batch failed.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/specbandit/worker.rb', line 31

def run
  if key_rerun
    rerun_files = queue.read_all(key_rerun)
    if rerun_files.any?
      run_replay(rerun_files)
    else
      run_steal(record: true)
    end
  else
    run_steal(record: false)
  end
end