embulk-input-zendesk 0.2.10 → 0.2.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/CHANGELOG.md +3 -0
- data/embulk-input-zendesk.gemspec +1 -1
- data/lib/embulk/input/zendesk/client.rb +19 -16
- data/test/embulk/input/zendesk/test_client.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bbd52d83f9670fdf5c7bad8bb916bbce2d2539c
|
4
|
+
data.tar.gz: 3ede177aa9ffe5d102a6bb68e62a256a209c68d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fe16f902ee028b8f13237f4bd8784ded62e96df33527da4459cd59044212193d1994b8d8129b8a008e7bb76ec099e04a69e8fc8fd7e4134889c65593f53fb13
|
7
|
+
data.tar.gz: 08d9ada788c89cb5eb1beabd3462b7a1731965e2ecd4171b4bc781de3621a1ac95ab7d4fa1b5b935a5d678b63346f37be46b83950a555f14fc885044cff45a44
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-9.
|
1
|
+
jruby-9.1.5.0
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
Gem::Specification.new do |spec|
|
3
3
|
spec.name = "embulk-input-zendesk"
|
4
|
-
spec.version = "0.2.
|
4
|
+
spec.version = "0.2.11"
|
5
5
|
spec.authors = ["uu59", "muga", "sakama"]
|
6
6
|
spec.summary = "Zendesk input plugin for Embulk"
|
7
7
|
spec.description = "Loads records from Zendesk."
|
@@ -130,7 +130,7 @@ module Embulk
|
|
130
130
|
|
131
131
|
def export_parallel(path, key, start_time = 0, &block)
|
132
132
|
per_page = 100 # 100 is maximum https://developer.zendesk.com/rest_api/docs/core/introduction#pagination
|
133
|
-
first_response = request(path, per_page: per_page, page: 1)
|
133
|
+
first_response = request(path, false, per_page: per_page, page: 1)
|
134
134
|
first_fetched = JSON.parse(first_response.body)
|
135
135
|
total_count = first_fetched["count"]
|
136
136
|
last_page_num = (total_count / per_page.to_f).ceil
|
@@ -143,7 +143,7 @@ module Embulk
|
|
143
143
|
execute_thread_pool do |pool|
|
144
144
|
(2..last_page_num).each do |page|
|
145
145
|
pool.post do
|
146
|
-
response = request(path, per_page: per_page, page: page)
|
146
|
+
response = request(path, false, per_page: per_page, page: page)
|
147
147
|
fetched_records = extract_records_from_response(response, key)
|
148
148
|
Embulk.logger.info "Fetched #{key} on page=#{page} >>> size: #{fetched_records.length}"
|
149
149
|
fetched_records.uniq { |r| r['id'] }.each do |record|
|
@@ -160,7 +160,7 @@ module Embulk
|
|
160
160
|
per_page = PARTIAL_RECORDS_SIZE
|
161
161
|
Embulk.logger.info("Fetching #{path} with page=#{page} (partial)")
|
162
162
|
|
163
|
-
response = request(path, per_page: per_page, page: page)
|
163
|
+
response = request(path, true, per_page: per_page, page: page)
|
164
164
|
|
165
165
|
begin
|
166
166
|
data = JSON.parse(response.body)
|
@@ -186,7 +186,7 @@ module Embulk
|
|
186
186
|
execute_thread_pool do |pool|
|
187
187
|
loop do
|
188
188
|
start_fetching = Time.now
|
189
|
-
response = request(path, query.merge(start_time: start_time))
|
189
|
+
response = request(path, false, query.merge(start_time: start_time))
|
190
190
|
actual_fetched = 0
|
191
191
|
data = JSON.parse(response.body)
|
192
192
|
# no key found in response occasionally => retry
|
@@ -261,7 +261,7 @@ module Embulk
|
|
261
261
|
httpclient
|
262
262
|
end
|
263
263
|
|
264
|
-
def request(path, query = {})
|
264
|
+
def request(path, partial = false, query = {})
|
265
265
|
u = URI.parse(config[:login_url])
|
266
266
|
u.path = path
|
267
267
|
|
@@ -277,8 +277,7 @@ module Embulk
|
|
277
277
|
retryer.with_retry do
|
278
278
|
Embulk.logger.debug "Fetching #{u.to_s}"
|
279
279
|
response = httpclient.get(u.to_s, query, extheader)
|
280
|
-
|
281
|
-
handle_response(response.status, response.headers, response.body)
|
280
|
+
handle_response(response.status, response.headers, response.body, partial)
|
282
281
|
response
|
283
282
|
end
|
284
283
|
end
|
@@ -312,8 +311,7 @@ module Embulk
|
|
312
311
|
next
|
313
312
|
end
|
314
313
|
end
|
315
|
-
handle_response(message.status, message.headers, chunk)
|
316
|
-
|
314
|
+
handle_response(message.status, message.headers, chunk, true)
|
317
315
|
buf << chunk
|
318
316
|
break if buf.bytesize > PARTIAL_RECORDS_BYTE_SIZE
|
319
317
|
end
|
@@ -349,13 +347,18 @@ module Embulk
|
|
349
347
|
result
|
350
348
|
end
|
351
349
|
|
352
|
-
def wait_rate_limit(retry_after)
|
353
|
-
|
354
|
-
|
355
|
-
|
350
|
+
def wait_rate_limit(retry_after, partial = false)
|
351
|
+
# Won't retry for preview/guess mode
|
352
|
+
if partial
|
353
|
+
raise Embulk::DataError.new("Rate Limited. Waiting #{retry_after} seconds to re-run")
|
354
|
+
else
|
355
|
+
Embulk.logger.warn "Rate Limited. Waiting #{retry_after} seconds to retry"
|
356
|
+
sleep retry_after
|
357
|
+
throw :retry
|
358
|
+
end
|
356
359
|
end
|
357
360
|
|
358
|
-
def handle_response(status_code, headers, body)
|
361
|
+
def handle_response(status_code, headers, body, partial = false)
|
359
362
|
# https://developer.zendesk.com/rest_api/docs/core/introduction#response-format
|
360
363
|
case status_code
|
361
364
|
when 200, 404
|
@@ -379,7 +382,7 @@ module Embulk
|
|
379
382
|
when 429
|
380
383
|
# rate limit
|
381
384
|
retry_after = headers["Retry-After"]
|
382
|
-
wait_rate_limit(retry_after.to_i)
|
385
|
+
wait_rate_limit(retry_after.to_i, partial)
|
383
386
|
when 400..500
|
384
387
|
# Won't retry for 4xx range errors except above. Almost they should be ConfigError e.g. 403 Forbidden
|
385
388
|
raise Embulk::ConfigError.new("[#{status_code}] #{body}")
|
@@ -387,7 +390,7 @@ module Embulk
|
|
387
390
|
# 503 is possible rate limit
|
388
391
|
retry_after = headers["Retry-After"]
|
389
392
|
if retry_after
|
390
|
-
wait_rate_limit(retry_after.to_i)
|
393
|
+
wait_rate_limit(retry_after.to_i, partial)
|
391
394
|
else
|
392
395
|
raise "[#{status_code}] temporally failure."
|
393
396
|
end
|
@@ -482,6 +482,14 @@ module Embulk
|
|
482
482
|
stub_response(429, ["Retry-After: #{after}"])
|
483
483
|
mock(client).sleep after.to_i
|
484
484
|
assert_throw(:retry) do
|
485
|
+
client.tickets(false, &proc{})
|
486
|
+
end
|
487
|
+
end
|
488
|
+
|
489
|
+
test "429 guess/preview fail fast" do
|
490
|
+
after = "123"
|
491
|
+
stub_response(429, ["Retry-After: #{after}"])
|
492
|
+
assert_raise(DataError.new("Rate Limited. Waiting #{after} seconds to re-run")) do
|
485
493
|
client.tickets(&proc{})
|
486
494
|
end
|
487
495
|
end
|
@@ -505,6 +513,14 @@ module Embulk
|
|
505
513
|
stub_response(503, ["Retry-After: #{after}"])
|
506
514
|
mock(client).sleep after.to_i
|
507
515
|
assert_throw(:retry) do
|
516
|
+
client.tickets(false, &proc{})
|
517
|
+
end
|
518
|
+
end
|
519
|
+
|
520
|
+
test "503 with Retry-After guess/preview fail fast" do
|
521
|
+
after = "123"
|
522
|
+
stub_response(503, ["Retry-After: #{after}"])
|
523
|
+
assert_raise(DataError.new("Rate Limited. Waiting #{after} seconds to re-run")) do
|
508
524
|
client.tickets(&proc{})
|
509
525
|
end
|
510
526
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: embulk-input-zendesk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
@@ -255,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
255
255
|
version: '0'
|
256
256
|
requirements: []
|
257
257
|
rubyforge_project:
|
258
|
-
rubygems_version: 2.
|
258
|
+
rubygems_version: 2.6.6
|
259
259
|
signing_key:
|
260
260
|
specification_version: 4
|
261
261
|
summary: Zendesk input plugin for Embulk
|