semaph 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13271774cf750f1f8eedc2d48de45ceeaa164af2593581cac85fc73e6c371d95
4
- data.tar.gz: 3afba979f087aba88acbeeb3a09e46261fda8ba3afae3cf1690ced82d687d420
3
+ metadata.gz: c0677122d6857a85e92dc0a74346b4f130f1f715ad9cfede85ffab143540867e
4
+ data.tar.gz: c6165a0966dd6cd3088fcece1d56d304188c79552c03a0d48cb3addbe1e4649f
5
5
  SHA512:
6
- metadata.gz: a00c84f6e8e357e0a99f921e316b8a36f8c5cf78a8d9befb33f2e8e25f733801024392401b4329d8faf20a690dace3c7b2fe48a1f31bb71dfa4c25f41987156b
7
- data.tar.gz: 8c904c17ba321fb240c4bdc1fa8ecb1beac95d6688da8632dd6e7e26446c2c16bd52bca36757eccc389cb06b64d3e1af4fc874ce817d706d632e28eaad2b56b5
6
+ metadata.gz: d2ea65f9d5fdaf2b4b0597dc3fd0205eaa7fad89b596dff1fcf6619c6d39d11c80c9b5f9acd4e375049c6e16a91bcc4df5708cfd6e1725e834c80576d1442dbf
7
+ data.tar.gz: 2505c4088ef17b9efdaa9c9d2dfc80159e459dfcc5f097d4761b69b2e390cb3371b611d9a913783812b5b1dd7435063ac8db3de2fb58f90168822068bcdc2ebf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- semaph (0.3.0)
4
+ semaph (0.4.0)
5
5
  faraday
6
6
  rainbow
7
7
  shell_shock
@@ -33,6 +33,14 @@ module Semaph
33
33
  ].compact.join(" ")
34
34
  end
35
35
 
36
+ def finished?
37
+ @status == "FINISHED"
38
+ end
39
+
40
+ def failed?
41
+ @result == "FAILED"
42
+ end
43
+
36
44
  # block_state can be waiting/running/done
37
45
  # block_result can be passed/failed/canceled/stopped
38
46
  def block_icon
@@ -3,7 +3,7 @@ require "semaph/model/job"
3
3
  module Semaph
4
4
  module Model
5
5
  class JobCollection
6
- attr_reader :all
6
+ attr_reader :all, :pipeline
7
7
 
8
8
  def initialize(pipeline)
9
9
  @pipeline = pipeline
@@ -16,11 +16,11 @@ module Semaph
16
16
  end
17
17
 
18
18
  def incomplete
19
- @all.reject { |job| job.status == "FINISHED" }
19
+ @all.reject(&:finished?)
20
20
  end
21
21
 
22
22
  def failed
23
- @all.select { |job| job.result == "FAILED" }
23
+ @all.select(&:failed?)
24
24
  end
25
25
 
26
26
  private
@@ -1,7 +1,9 @@
1
+ require "fileutils"
2
+
1
3
  module Semaph
2
4
  module Shells
3
5
  module Pipeline
4
- class JobsLogsCommand
6
+ class JobLogCommand
5
7
  attr_reader :usage, :help
6
8
 
7
9
  def initialize(job_collection)
@@ -20,8 +22,18 @@ module Semaph
20
22
  return
21
23
  end
22
24
 
23
- filename = "#{job.id}.log"
24
- File.open(filename, "w") { |file| file.puts job.log } unless File.exist?(filename)
25
+ unless job.finished?
26
+ puts "This job has not finished yet"
27
+ return
28
+ end
29
+
30
+ base = "tmp/logs/pipeline/#{job.pipeline.id}"
31
+ FileUtils.mkdir_p(base)
32
+ filename = "#{base}/#{job.id}.log"
33
+ unless File.exist?(filename)
34
+ puts "retrieving log for job #{job.id}"
35
+ File.open(filename, "w") { |file| file.puts job.log }
36
+ end
25
37
  system("less #{filename}")
26
38
  end
27
39
  end
@@ -0,0 +1,34 @@
1
+ require "fileutils"
2
+
3
+ module Semaph
4
+ module Shells
5
+ module Pipeline
6
+ class JobLogGrepCommand
7
+ attr_reader :usage, :help, :job_collection
8
+
9
+ def initialize(job_collection)
10
+ @job_collection = job_collection
11
+ @usage = "<expression>"
12
+ @help = "retrieve all logs and grep for text"
13
+ end
14
+
15
+ def execute(expression)
16
+ base = "tmp/logs/pipeline/#{job_collection.pipeline.id}"
17
+ FileUtils.mkdir_p(base)
18
+ @job_collection.all.each do |job|
19
+ unless job.finished?
20
+ puts "skipping incomplete job #{job.id}"
21
+ next
22
+ end
23
+ filename = "#{base}/#{job.id}.log"
24
+ unless File.exist?(filename)
25
+ puts "retrieving log for job #{job.id}"
26
+ File.open(filename, "w") { |file| file.puts job.log }
27
+ end
28
+ end
29
+ system("ag #{expression} #{base} | less")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,8 @@
1
1
  require "semaph/commands/reload_command"
2
2
  require "semaph/commands/rerun_workflow_command"
3
3
  require "semaph/shells/pipeline/jobs_list_command"
4
- require "semaph/shells/pipeline/jobs_logs_command"
4
+ require "semaph/shells/pipeline/job_log_command"
5
+ require "semaph/shells/pipeline/job_log_grep_command"
5
6
  require "semaph/shells/pipeline/jobs_poll_command"
6
7
  require "shell_shock/context"
7
8
 
@@ -38,7 +39,8 @@ module Semaph
38
39
  @jobs_list_command = JobsListCommand.new(job_collection)
39
40
  add_command @jobs_list_command, "list-jobs"
40
41
  add_command JobsPollCommand.new(job_collection), "poll-jobs"
41
- add_command JobsLogsCommand.new(job_collection), "jobs-logs"
42
+ add_command JobLogCommand.new(job_collection), "job-log"
43
+ add_command JobLogGrepCommand.new(job_collection), "grep-logs"
42
44
  add_command ::Semaph::Commands::RerunWorkflowCommand.new(workflow), "rerun"
43
45
  add_open_branch_command
44
46
  add_open_workflow_command
@@ -1,3 +1,3 @@
1
1
  module Semaph
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semaph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Ryall
@@ -109,8 +109,9 @@ files:
109
109
  - lib/semaph/shells/organisations/organisations_list_command.rb
110
110
  - lib/semaph/shells/organisations/organisations_select_command.rb
111
111
  - lib/semaph/shells/organisations/organisations_shell.rb
112
+ - lib/semaph/shells/pipeline/job_log_command.rb
113
+ - lib/semaph/shells/pipeline/job_log_grep_command.rb
112
114
  - lib/semaph/shells/pipeline/jobs_list_command.rb
113
- - lib/semaph/shells/pipeline/jobs_logs_command.rb
114
115
  - lib/semaph/shells/pipeline/jobs_poll_command.rb
115
116
  - lib/semaph/shells/pipeline/pipeline_shell.rb
116
117
  - lib/semaph/shells/project/project_shell.rb