embulk-input-buildkite 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: 8181f9bd9a42836709a5deb133f20a93d4465e1087eaaa2701f77af0f9c30d86
4
- data.tar.gz: 4dbcd67665f3659150e92b1ea04adb42df2bbff9d9494b713e3dec8f4e96b388
3
+ metadata.gz: 5ad00bb2939704ea96a218b7825190027e7fe47c44cc9a5fad3128805e728360
4
+ data.tar.gz: afcc34e688f3bee95aeb78d5d4d0d29cbac22ab372b12cdd034cf29a0b0cfc6d
5
5
  SHA512:
6
- metadata.gz: 58ecb609e666d22b57fe8f4197cc0a4cb6a3fbc782c4e88dd97bccbe342e771cf1731a644d69a7fb81bfdb4b73fb6b531576a5fd2716991a17dc24a6a3754fdf
7
- data.tar.gz: 3375bf15b396417cd9890505de0829eee94317ebf67c890243e19f96130107d43ec9d5b4d5c4b76ec61d5a0643f7caeb7c5bcaa2f51afda6ec7fce7ce41b53e0
6
+ metadata.gz: e4a0161cb327a962851529d364f426672bbd277e147eacdc4974ffc22574519b2440a414c98936b12452242f542cb5184e5597af11eb0a95d62cdc69fb0290cd
7
+ data.tar.gz: 067a7064167107a9999d348ddc711fc6764102751d0363b8f8261e802629c49be7797fac331b889b14087c3b135db487c348ddac841270a9e78353d566a23af6
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.4.0
2
+
3
+ - Add retry
4
+ - Add artifact_download_concurrency option
5
+
1
6
  # 0.3.0
2
7
 
3
8
  - Add artifacts
data/README.md CHANGED
@@ -15,6 +15,7 @@ Fetch Buildkite build results
15
15
  - **pipeline_slug**: Target pipeline name like `rails` (string, required)
16
16
  - **build_nums**: Build numbers (Array of integer, required)
17
17
  - **token**: Buildkite API token which can be found on https://buildkite.com/user/api-access-tokens (string, required)
18
+ - **artifact_download_concurrency**: Artifact download concurrency (integer, optional, default: 10)
18
19
 
19
20
  ## Example
20
21
 
data/docker-compose.yml CHANGED
@@ -1,4 +1,4 @@
1
- version: "3.7"
1
+ version: "2.4"
2
2
  services:
3
3
  embulk:
4
4
  build: .
@@ -12,6 +12,7 @@ services:
12
12
  environment:
13
13
  BUNDLE_PATH: /vendor/bundle
14
14
  env_file: app.env
15
+ mem_limit: 512M
15
16
  volumes:
16
17
  home:
17
18
  vendor:
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-input-buildkite"
4
- spec.version = "0.3.0"
4
+ spec.version = "0.4.0"
5
5
  spec.authors = ["Fumiaki MATSUSHIMA"]
6
6
  spec.summary = "Buildkite input plugin for Embulk"
7
7
  spec.description = "Loads records from Buildkite."
@@ -4,13 +4,17 @@ module Embulk
4
4
  module Input
5
5
 
6
6
  class Buildkite < InputPlugin
7
+ MAX_RETRY = 5
8
+
7
9
  class Logger
8
10
  def initialize(embulk_logger)
9
11
  @embulk_logger = embulk_logger
10
12
  end
11
13
 
12
- def info(message)
13
- @embulk_logger.info("embulk-input-buildkite: #{message}")
14
+ %w(info warn error).each do |m|
15
+ define_method(m) do |message|
16
+ @embulk_logger.send(m, "embulk-input-buildkite: #{message}")
17
+ end
14
18
  end
15
19
  end
16
20
 
@@ -22,7 +26,8 @@ module Embulk
22
26
  "org_slug" => config.param("org_slug", :string),
23
27
  "pipeline_slug" => config.param("pipeline_slug", :string),
24
28
  "build_nums" => config.param("build_nums", :array),
25
- "token" => config.param("token", :string, nil),
29
+ "token" => config.param("token", :string),
30
+ "artifact_download_concurrency" => config.param("artifact_download_concurrency", :integer, default: 10),
26
31
  }
27
32
 
28
33
  columns = [
@@ -63,14 +68,25 @@ module Embulk
63
68
  task['build_nums'].each do |build_num|
64
69
  logger.info("Start build_num:[#{build_num}]")
65
70
 
66
- build = client.fetch_build(number: build_num)
71
+ build = with_retry { client.fetch_build(number: build_num) }
67
72
  build[:jobs].each do |job|
68
73
  logger.info("Start Start job_id:[#{job[:id]}]")
69
- log = client.fetch_log(build_number: job[:build_number], job_id: job[:id])
70
- artifacts = client.fetch_artifacts(build_number: job[:build_number], job_id: job[:id])
71
- artifacts.each do |artifact|
72
- artifact.merge!(body: client.fetch_artifact(build_number: job[:build_number], job_id: job[:id], artifact_id: artifact[:id]))
74
+ log = with_retry { client.fetch_log(build_number: job[:build_number], job_id: job[:id]) }
75
+ artifacts = with_retry { client.fetch_artifacts(build_number: job[:build_number], job_id: job[:id]) }
76
+
77
+ queue = Queue.new
78
+ artifacts.each {|a| queue.push(a) }
79
+ workers = Array.new(task['artifact_download_concurrency']) do
80
+ Thread.new do
81
+ begin
82
+ while artifact = queue.pop(true)
83
+ artifact[:body] = with_retry { client.fetch_artifact(build_number: job[:build_number], job_id: job[:id], artifact_id: artifact[:id]) }
84
+ end
85
+ rescue ThreadError
86
+ end
87
+ end
73
88
  end
89
+ workers.each(&:join)
74
90
 
75
91
  page_builder.add([
76
92
  job[:id],
@@ -101,6 +117,24 @@ module Embulk
101
117
  def logger
102
118
  @logger ||= Logger.new(Embulk.logger)
103
119
  end
120
+
121
+ def with_retry(&block)
122
+ retries = 0
123
+ begin
124
+ yield
125
+ rescue => e
126
+ sleep retries
127
+
128
+ if retries < MAX_RETRY
129
+ retries += 1
130
+ logger.warn("retry ##{retries}, #{e.message}")
131
+ retry
132
+ else
133
+ logger.error("retry exhausted ##{retries}, #{e.message}")
134
+ raise e
135
+ end
136
+ end
137
+ end
104
138
  end
105
139
 
106
140
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-buildkite
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
  - Fumiaki MATSUSHIMA