Class: Semaph::Shells::Pipeline::JobLogGrepCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/semaph/shells/pipeline/job_log_grep_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_collection, scope) ⇒ JobLogGrepCommand

Returns a new instance of JobLogGrepCommand.



7
8
9
10
11
12
# File 'lib/semaph/shells/pipeline/job_log_grep_command.rb', line 7

def initialize(job_collection, scope)
  @job_collection = job_collection
  @scope = scope
  @usage = "<expression>"
  @help = "retrieve logs for #{scope} jobs and grep for text"
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



5
6
7
# File 'lib/semaph/shells/pipeline/job_log_grep_command.rb', line 5

def help
  @help
end

#job_collectionObject (readonly)

Returns the value of attribute job_collection.



5
6
7
# File 'lib/semaph/shells/pipeline/job_log_grep_command.rb', line 5

def job_collection
  @job_collection
end

#usageObject (readonly)

Returns the value of attribute usage.



5
6
7
# File 'lib/semaph/shells/pipeline/job_log_grep_command.rb', line 5

def usage
  @usage
end

Instance Method Details

#execute(expression) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/semaph/shells/pipeline/job_log_grep_command.rb', line 14

def execute(expression)
  base = "tmp/logs/pipeline/#{job_collection.pipeline.id}"
  @job_collection.send(@scope).each do |job|
    unless job.finished?
      puts "skipping incomplete job #{job.id}"
      next
    end
    job.write_log(base)
  end
  system("ag #{expression} #{base} | less")
end