peoplegroup-connectors 0.1.36 → 0.1.37

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: 8611752b4ca5e726cc88207388a89cb90a7ad49cfa57681409b857ee13d59c8e
4
- data.tar.gz: adb086e3c860033292caff493bf483967223b11b534828b11db5a9f3ffca7ac0
3
+ metadata.gz: 5ee402cbc096def361f487eda8ef9992ff459ab63a606f0ad94d4735d41bc365
4
+ data.tar.gz: a79c17d291849c27a2996da26c814dbf70e7ad1c27a2782ba502492407010c1a
5
5
  SHA512:
6
- metadata.gz: c4e1c9ab9341dc9731695024237f6f2d9f7febc87821926c5205dd345725affcfcc66732787fdf12bf3bcfaddbc01c27ff3409b38a900738980d187771219a66
7
- data.tar.gz: b05f29c43918c58229fa3486b2935f0945355b31a925fc55fa1e0f38f10df45321548611ed34f50f715560da04ebd2b2f6ea85ce3a450d275885e66a996dbe3a
6
+ metadata.gz: 18b42324f2bb9db2c8e158df26d8ca5b35efa869fc3358afd4c94a44dd810487cb0138a80b7c977b274c43e4a3e86c9a15301528b2b465c8a1fd9e245fdde53a
7
+ data.tar.gz: 68c8545dbb12e870978a589872fdabcd2ff5fa9ea93e1dcd7c3fe90a3f758bd5cdf7b78edfee2ab9d57292a8a903eea6495974d5559e7c4b59e56cdc70d31778
@@ -6,6 +6,7 @@ require_relative 'connectors/slack'
6
6
  require_relative 'connectors/pto_roots'
7
7
  require_relative 'connectors/bamboo'
8
8
  require_relative 'connectors/greenhouse'
9
+ require_relative 'utils'
9
10
 
10
11
  module PeopleGroup
11
12
  module Connectors
@@ -5,8 +5,6 @@ require 'bamboozled'
5
5
  module PeopleGroup
6
6
  module Connectors
7
7
  class Bamboo
8
- MAX_RETRIES = 3
9
-
10
8
  def initialize(use_report: false)
11
9
  @use_report = use_report
12
10
  @client = Bamboozled.client(subdomain: 'gitlab', api_key: ENV['BAMBOO_API_KEY'])
@@ -83,16 +81,12 @@ module PeopleGroup
83
81
  end
84
82
 
85
83
  def employees
86
- retries = 0
87
-
88
- begin
84
+ Utils.retry_on_error(errors: [Net::ReadTimeout, Bamboozled::GatewayError]) do
89
85
  if @use_report
90
86
  @employees ||= @client.report.find(@use_report, 'JSON', true).reject { |employee| employee['lastName'] == 'Test-Gitlab' }
91
87
  else
92
88
  @employees ||= @client.report.custom(fields, 'JSON').reject { |employee| employee['lastName'] == 'Test-Gitlab' }
93
89
  end
94
- rescue Net::ReadTimeout, Bamboozled::GatewayError
95
- retry if (retries += 1) < MAX_RETRIES
96
90
  end
97
91
  end
98
92
 
@@ -7,8 +7,6 @@ module PeopleGroup
7
7
  class GitLab
8
8
  attr_accessor :client
9
9
 
10
- MAX_RETRIES = 3
11
-
12
10
  API_URL = ENV['GITLAB_API_V4_URL'] || 'https://gitlab.com/api/v4'
13
11
 
14
12
  def initialize(token: ENV['GITLAB_API_TOKEN'])
@@ -144,14 +142,8 @@ module PeopleGroup
144
142
 
145
143
  private
146
144
 
147
- def retry_on_error
148
- retries = 0
149
-
150
- begin
151
- yield
152
- rescue Gitlab::Error::InternalServerError
153
- retry if (retries += 1) < MAX_RETRIES
154
- end
145
+ def retry_on_error(&block)
146
+ Utils.retry_on_error(errors: [Gitlab::Error::InternalServerError], &block)
155
147
  end
156
148
 
157
149
  def find_epic(group_id, title)
@@ -19,20 +19,19 @@ module PeopleGroup
19
19
  def hired_candidates(updated_since)
20
20
  page = 1
21
21
  candidates = []
22
- retries = 0
22
+ on_error = -> { p [updated_since, page] }
23
23
 
24
24
  loop do
25
- begin
26
- results = @client.candidates(nil, updated_after: updated_since, page: page)
27
- break if results.empty?
28
-
29
- results.each do |candidate|
30
- candidates << candidate if hired_non_active?(candidate)
31
- end
32
- rescue GreenhouseIo::Error
33
- p [updated_since, page]
34
- retry if (retries += 1) < MAX_RETRIES
25
+ results = Utils.retry_on_error(errors: [GreenhouseIo::Error], on_error: on_error) do
26
+ @client.candidates(nil, updated_after: updated_since, page: page)
35
27
  end
28
+
29
+ break if results.empty?
30
+
31
+ results.each do |candidate|
32
+ candidates << candidate if hired_non_active?(candidate)
33
+ end
34
+
36
35
  page += 1
37
36
  end
38
37
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module PeopleGroup
4
4
  module Connectors
5
- VERSION = '0.1.36'
5
+ VERSION = '0.1.37'
6
6
  end
7
7
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PeopleGroup
4
+ class Utils
5
+ class << self
6
+ def retry_on_error(max_attempts: 3, delay: 0, errors: [StandardError], on_error: -> {})
7
+ attempts = 0
8
+
9
+ begin
10
+ yield
11
+ rescue *errors => e
12
+ on_error.call
13
+ sleep delay
14
+ retry if (attempts += 1) < max_attempts
15
+ raise e
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peoplegroup-connectors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.36
4
+ version: 0.1.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - lien van den steen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-19 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitlab
@@ -167,6 +167,7 @@ files:
167
167
  - lib/peoplegroup/connectors/pto_roots.rb
168
168
  - lib/peoplegroup/connectors/slack.rb
169
169
  - lib/peoplegroup/connectors/version.rb
170
+ - lib/peoplegroup/utils.rb
170
171
  homepage: https://gitlab.com/gitlab-com/people-group/peopleops-eng/connectors-gem
171
172
  licenses:
172
173
  - MIT
@@ -174,7 +175,7 @@ metadata:
174
175
  homepage_uri: https://gitlab.com/gitlab-com/people-group/peopleops-eng/connectors-gem
175
176
  source_code_uri: https://gitlab.com/gitlab-com/people-group/peopleops-eng/connectors-gem
176
177
  changelog_uri: https://gitlab.com/gitlab-com/people-group/peopleops-eng/connectors-gem
177
- post_install_message:
178
+ post_install_message:
178
179
  rdoc_options: []
179
180
  require_paths:
180
181
  - lib
@@ -190,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
191
  version: '0'
191
192
  requirements: []
192
193
  rubygems_version: 3.1.4
193
- signing_key:
194
+ signing_key:
194
195
  specification_version: 4
195
196
  summary: Library for our shared connectors.
196
197
  test_files: []