Class: Travis::Surveillance::Job

Inherits:
Object
  • Object
show all
Defined in:
lib/travis/surveillance/job.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

ATTRIBUTES =
[:build, :finished_at, :id, :number, :result, :started_at]

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Job

Returns a new instance of Job.



22
23
24
25
26
# File 'lib/travis/surveillance/job.rb', line 22

def initialize(attrs = {})
  self.attributes = attrs

  populate
end

Instance Method Details

#attributes=(attrs = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/travis/surveillance/job.rb', line 28

def attributes=(attrs = {})
  attrs.each do |key, value|
    next if value.nil?
    if key == 'config'
      config.attributes = value
    else
      send("#{key}=", (key[/_at$/] ? Time.parse(value) : value)) if ATTRIBUTES.include?(key.to_sym)
    end
  end
end

#configObject



39
40
41
# File 'lib/travis/surveillance/job.rb', line 39

def config
  @config ||= Config.new
end

#durationObject



43
44
45
46
47
48
49
50
51
# File 'lib/travis/surveillance/job.rb', line 43

def duration
  if started_at && finished_at
    finished_at - started_at
  elsif started_at
    Time.now - started_at
  else
    nil
  end
end

#failed?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/travis/surveillance/job.rb', line 53

def failed?
  !result.nil? && !passed?
end

#passed?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/travis/surveillance/job.rb', line 57

def passed?
  !result.nil? && result.zero?
end

#running?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/travis/surveillance/job.rb', line 61

def running?
  result.nil?
end

#runtimeObject



65
66
67
68
69
70
71
72
73
# File 'lib/travis/surveillance/job.rb', line 65

def runtime
  return @runtime if @runtime
  @runtime = build.config.language.dup
  case @runtime
  when "ruby"
    @runtime << " #{config.rvm}"
  end
  @runtime
end

#stateObject



75
76
77
78
79
80
81
82
83
# File 'lib/travis/surveillance/job.rb', line 75

def state
  if running?
    'running'
  elsif passed?
    'passed'
  else
    'failed'
  end
end