barbeque 1.2.1 → 1.2.2

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
  SHA1:
3
- metadata.gz: 0a2d49fbe13b55d7fbcc1b00150bc61f2345136c
4
- data.tar.gz: 6af129b187c7367753e9474bfe484bcedca466a4
3
+ metadata.gz: b27aeb159c85a1b575e449c041347a150842b86e
4
+ data.tar.gz: a19d444c16ebc67456f51caf69c36163ae30b953
5
5
  SHA512:
6
- metadata.gz: a2b3986cc9434d160b9e5b7efdb3b74513f522eaacd8caf07a4bb641b4d6f2807c09d1d5255787c1a730a9aa3639a92ce0ce26dd011587a7365d0f7d322ed820
7
- data.tar.gz: 1f6cf3e3279464919f88782a61eda99c4c464dc743aecc37325226ae92879aad56d4d8d00d69a67d121206f4725fda16170e7268abb59ff5cea2d43463c5f74b
6
+ metadata.gz: ca444daf5808c8875d9e027baf783eae542b6d375aaf2aaf912fc6067211c461dfbe18c87a81cf0c378a60fa440565b35e3387270b94fd0efdfe2fba9f294c8b
7
+ data.tar.gz: 4ab3dfe060908257447481b0eba56a3c5639d3b217739ab510b42a0971c5b71ea78a3cb5967191188546d489c615a4c90d8c6d72e7c782f0d315344f31bbdd18
@@ -1,6 +1,7 @@
1
1
  require 'aws-sdk'
2
2
  require 'active_support'
3
3
  require 'active_support/core_ext'
4
+ require 'barbeque/exception_handler'
4
5
 
5
6
  module Barbeque
6
7
  class ExecutionLog
@@ -1,8 +1,8 @@
1
1
  require 'barbeque/docker_image'
2
2
  require 'barbeque/execution_log'
3
+ require 'barbeque/hako_s3_client'
3
4
  require 'barbeque/slack_notifier'
4
5
  require 'open3'
5
- require 'uri'
6
6
 
7
7
  module Barbeque
8
8
  module Executor
@@ -10,6 +10,8 @@ module Barbeque
10
10
  class HakoCommandError < StandardError
11
11
  end
12
12
 
13
+ attr_reader :hako_s3_client
14
+
13
15
  # @param [String] hako_dir
14
16
  # @param [Hash] hako_env
15
17
  # @param [String] yaml_dir
@@ -17,10 +19,7 @@ module Barbeque
17
19
  @hako_dir = hako_dir
18
20
  @hako_env = hako_env
19
21
  @yaml_dir = yaml_dir
20
- uri = URI.parse(oneshot_notification_prefix)
21
- @s3_bucket = uri.host
22
- @s3_prefix = uri.path.sub(%r{\A/}, '')
23
- @s3_region = URI.decode_www_form(uri.query || '').to_h['region']
22
+ @hako_s3_client = HakoS3Client.new(oneshot_notification_prefix)
24
23
  end
25
24
 
26
25
  # @param [Barbeque::JobExecution] job_execution
@@ -69,10 +68,8 @@ module Barbeque
69
68
  # @param [Barbeque::JobExecution] job_execution
70
69
  def poll_execution(job_execution)
71
70
  hako_task = Barbeque::EcsHakoTask.find_by!(message_id: job_execution.message_id)
72
- result = get_stopped_result(hako_task)
73
- if result
74
- detail = result.fetch('detail')
75
- task = Aws::Json::Parser.new(Aws::ECS::Client.api.operation('describe_tasks').output.shape.member(:tasks).shape.member).parse(JSON.dump(detail))
71
+ task = @hako_s3_client.get_stopped_result(hako_task)
72
+ if task
76
73
  status = :failed
77
74
  task.containers.each do |container|
78
75
  if container.name == 'app'
@@ -88,10 +85,8 @@ module Barbeque
88
85
  def poll_retry(job_retry)
89
86
  hako_task = Barbeque::EcsHakoTask.find_by!(message_id: job_retry.message_id)
90
87
  job_execution = job_retry.job_execution
91
- result = get_stopped_result(hako_task)
92
- if result
93
- detail = result.fetch('detail')
94
- task = Aws::Json::Parser.new(Aws::ECS::Client.api.operation('describe_tasks').output.shape.member(:tasks).shape.member).parse(JSON.dump(detail))
88
+ task = @hako_s3_client.get_stopped_result(hako_task)
89
+ if task
95
90
  status = :failed
96
91
  task.containers.each do |container|
97
92
  if container.name == 'app'
@@ -121,21 +116,6 @@ module Barbeque
121
116
  end
122
117
  end
123
118
 
124
- def s3_key_for_stopped_result(hako_task)
125
- "#{@s3_prefix}/#{hako_task.task_arn}/stopped.json"
126
- end
127
-
128
- def s3_client
129
- @s3_client ||= Aws::S3::Client.new(region: @s3_region, http_read_timeout: 5)
130
- end
131
-
132
- def get_stopped_result(hako_task)
133
- object = s3_client.get_object(bucket: @s3_bucket, key: s3_key_for_stopped_result(hako_task))
134
- JSON.parse(object.body.read)
135
- rescue Aws::S3::Errors::NoSuchKey
136
- nil
137
- end
138
-
139
119
  def extract_task_info(stdout)
140
120
  last_line = stdout.lines.last
141
121
  if last_line
@@ -0,0 +1,35 @@
1
+ require 'uri'
2
+
3
+ module Barbeque
4
+ class HakoS3Client
5
+ # @param [String] oneshot_notification_prefix S3 location for oneshot notification
6
+ def initialize(oneshot_notification_prefix)
7
+ uri = URI.parse(oneshot_notification_prefix)
8
+ @s3_bucket = uri.host
9
+ @s3_prefix = uri.path.sub(%r{\A/}, '')
10
+ @s3_region = URI.decode_www_form(uri.query || '').to_h['region']
11
+ end
12
+
13
+ # @param [Barbeque::EcsHakoTask] hako_task
14
+ # @return [String]
15
+ def s3_key_for_stopped_result(hako_task)
16
+ "#{@s3_prefix}/#{hako_task.task_arn}/stopped.json"
17
+ end
18
+
19
+ # @return [Aws::S3::Client]
20
+ def s3_client
21
+ @s3_client ||= Aws::S3::Client.new(region: @s3_region, http_read_timeout: 5)
22
+ end
23
+
24
+ # @param [Barbeque::EcsHakoTask] hako_task
25
+ # @return [Aws::ECS::Types::Task, nil]
26
+ def get_stopped_result(hako_task)
27
+ object = s3_client.get_object(bucket: @s3_bucket, key: s3_key_for_stopped_result(hako_task))
28
+ result = JSON.parse(object.body.read)
29
+ detail = result.fetch('detail')
30
+ Aws::Json::Parser.new(Aws::ECS::Client.api.operation('describe_tasks').output.shape.member(:tasks).shape.member).parse(JSON.dump(detail))
31
+ rescue Aws::S3::Errors::NoSuchKey
32
+ nil
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Barbeque
2
- VERSION = '1.2.1'
2
+ VERSION = '1.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barbeque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: adminlte2-rails
@@ -373,6 +373,7 @@ files:
373
373
  - lib/barbeque/executor.rb
374
374
  - lib/barbeque/executor/docker.rb
375
375
  - lib/barbeque/executor/hako.rb
376
+ - lib/barbeque/hako_s3_client.rb
376
377
  - lib/barbeque/message.rb
377
378
  - lib/barbeque/message/base.rb
378
379
  - lib/barbeque/message/invalid_message.rb