Class: Patir::CommandSequenceStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/patir/command.rb

Overview

CommandSequenceStatus represents the status of a CommandSequence, including the status of all the steps for this sequence.

In order to extract the status from steps, classes should quack to the rythm of Command. CommandSequenceStatus does this, so you can nest Stati

The status of an action sequence is :not_executed, :running, :success, :warning or :error and represents the overall status

:not_executed is set when all steps are :not_executed

:running is set while the sequence is running.

Upon completion or interruption one of :success, :error or :warning will be set.

:success is set when all steps are succesfull.

:warning is set when at least one step generates warnings and there are no failures.

:error is set when after execution at least one step has the :error status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sequence_name, steps = nil) ⇒ CommandSequenceStatus

You can pass an array of Commands to initialize CommandSequenceStatus



326
327
328
329
330
331
332
333
334
335
336
# File 'lib/patir/command.rb', line 326

def initialize sequence_name,steps=nil
  @sequence_name=sequence_name
  @sequence_runner=""
  @sequence_id=nil
  @step_states||=Hash.new
  #not run yet
  @status=:not_executed
  #translate the array of steps as we need it in number=>state form
  steps.each{|step| self.step=step } if steps
  @start_time=Time.now
end

Instance Attribute Details

#sequence_idObject

Returns the value of attribute sequence_id.



324
325
326
# File 'lib/patir/command.rb', line 324

def sequence_id
  @sequence_id
end

#sequence_nameObject

Returns the value of attribute sequence_name.



324
325
326
# File 'lib/patir/command.rb', line 324

def sequence_name
  @sequence_name
end

#sequence_runnerObject

Returns the value of attribute sequence_runner.



324
325
326
# File 'lib/patir/command.rb', line 324

def sequence_runner
  @sequence_runner
end

#start_timeObject

Returns the value of attribute start_time.



324
325
326
# File 'lib/patir/command.rb', line 324

def start_time
  @start_time
end

#statusObject

Returns the value of attribute status.



324
325
326
# File 'lib/patir/command.rb', line 324

def status
  @status
end

#step_statesObject

Returns the value of attribute step_states.



324
325
326
# File 'lib/patir/command.rb', line 324

def step_states
  @step_states
end

#stop_timeObject

Returns the value of attribute stop_time.



324
325
326
# File 'lib/patir/command.rb', line 324

def stop_time
  @stop_time
end

#strategyObject

Returns the value of attribute strategy.



324
325
326
# File 'lib/patir/command.rb', line 324

def strategy
  @strategy
end

Instance Method Details

#completed?Boolean

A sequence is considered completed when:

a step has errors and the :fail_on_error strategy is used

a step has warnings and the :fail_on_warning strategy is used

in all other cases if none of the steps has a :not_executed or :running status

Returns:

  • (Boolean)


354
355
356
357
358
359
360
361
362
363
# File 'lib/patir/command.rb', line 354

def completed?
  #this saves us iterating once+1 when no execution took place
  return false if !self.executed?
  @step_states.each do |state|
    return true if state[1][:status]==:error && state[1][:strategy]==:fail_on_error
    return true if state[1][:status]==:warning && state[1][:strategy]==:fail_on_warning
  end
  @step_states.each{|state| return false if state[1][:status]==:not_executed || state[1][:status]==:running }
  return true
end

#errorObject



426
427
428
# File 'lib/patir/command.rb', line 426

def error
  return ""
end

#exec_timeObject



413
414
415
416
# File 'lib/patir/command.rb', line 413

def exec_time
  return @stop_time-@start_time if @stop_time
  return 0
end

#executed?Boolean

Returns:

  • (Boolean)


429
430
431
432
# File 'lib/patir/command.rb', line 429

def executed?
  return true unless @status==:not_executed
  return false
end

#nameObject



417
418
419
# File 'lib/patir/command.rb', line 417

def name
  return @sequence_name
end

#numberObject



420
421
422
# File 'lib/patir/command.rb', line 420

def number
  return @sequence_id
end

#outputObject



423
424
425
# File 'lib/patir/command.rb', line 423

def output
  return self.summary
end

#running?Boolean

Returns:

  • (Boolean)


337
338
339
340
# File 'lib/patir/command.rb', line 337

def running?
  return true if :running==@status
  return false
end

#step=(step) ⇒ Object

Adds a step to the state. The step state is inferred from the Command instance __step__



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/patir/command.rb', line 370

def step=step
@step_states[step.number]={:name=>step.name,
  :status=>step.status,
  :output=>step.output,
  :duration=>step.exec_time,
  :error=>step.error,
  :strategy=>step.strategy}
  #this way we don't have to compare all the step states we always get the worst last stable state
  #:not_executed<:success<:warning<:success
  @previous_status=@status unless @status==:running
  case step.status
  when :running
    @status=:running
  when :warning
    @status=:warning unless @status==:error
    @status=:error if @previous_status==:error
  when :error
    @status=:error
  when :success
    @status=:success unless @status==:error || @status==:warning
    @status=:warning if @previous_status==:warning
    @status=:error if @previous_status==:error
  when :not_executed
    @status=@previous_status
  end
end

#step_state(number) ⇒ Object

A nil means there is no step with that number



365
366
367
368
# File 'lib/patir/command.rb', line 365

def step_state number
  s=@step_states[number] if @step_states[number]
  return s
end

#success?Boolean

true is returned when all steps were succesfull.

Returns:

  • (Boolean)


342
343
344
345
# File 'lib/patir/command.rb', line 342

def success?
  return true if :success==@status
  return false
end

#summaryObject

produces a brief text summary for this status



397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/patir/command.rb', line 397

def summary
  sum=""
  sum<<"#{@sequence_id}:" if @sequence_id
  sum<<"#{@sequence_name}. " unless @sequence_name.empty?
  sum<<"Status - #{@status}" 
  if !@step_states.empty? && @status!=:not_executed
    sum<<". States #{@step_states.size}\nStep status summary:"
    @step_states.each do |number,state|
      sum<<"\n\t#{number}:'#{state[:name]}' - #{state[:status]}"
    end
  end 
  return sum
end

#to_sObject



410
411
412
# File 'lib/patir/command.rb', line 410

def to_s
  "'#{sequence_id}':'#{@sequence_name}' on '#{@sequence_runner}' started at #{@start_time}.#{@step_states.size} steps"
end