embulk-input-zendesk 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +18 -17
- data/test/embulk/input/zendesk/test_client.rb +35 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eae8ef806e71aa366b06bc45075e36020c783c11
|
4
|
+
data.tar.gz: d8584f430c482719f7ec2c8ec2c441cfbe7f1a02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 293666013500b2074377043e545198e394b3e65876c916630b69cc922ec0639887f4101104e419f5d45f5ed95bc05197b528bb794bb9d2361bfa4fd1a939b6e6
|
7
|
+
data.tar.gz: 9ab732489802ac3cb5ec658785d1d8b09e3331bcf90362165fb3c92477b44ea7f1887aeb47b5e658f12f83b1b3e9c4ed7a813d50fbb9663401a211e9923f3fc9
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
jruby-9.1.
|
1
|
+
jruby-9.1.17.0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
## 0.2.14 - 2019-01-25
|
2
|
+
* [fixed] Disable pagination and add `dedup` option for non-incremental targets [#49](https://github.com/treasure-data/embulk-input-zendesk/pull/49)
|
3
|
+
|
1
4
|
## 0.2.13 - 2019-01-14
|
2
5
|
* [enhancement] Add `dedup` option, in order to avoid OOM when importing large dataset [#48](https://github.com/treasure-data/embulk-input-zendesk/pull/48)
|
3
6
|
|
@@ -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.14"
|
5
5
|
spec.authors = ["uu59", "muga", "sakama"]
|
6
6
|
spec.summary = "Zendesk input plugin for Embulk"
|
7
7
|
spec.description = "Loads records from Zendesk."
|
@@ -104,12 +104,12 @@ module Embulk
|
|
104
104
|
|
105
105
|
# they have non-incremental API only
|
106
106
|
UNAVAILABLE_INCREMENTAL_EXPORT.each do |target|
|
107
|
-
define_method(target) do |partial = true, start_time = 0, &block|
|
107
|
+
define_method(target) do |partial = true, start_time = 0, dedup = true, &block|
|
108
108
|
path = "/api/v2/#{target}.json"
|
109
109
|
if partial
|
110
110
|
export(path, target, &block)
|
111
111
|
else
|
112
|
-
export_parallel(path, target, start_time, &block)
|
112
|
+
export_parallel(path, target, start_time, dedup, false, &block)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -129,26 +129,27 @@ module Embulk
|
|
129
129
|
|
130
130
|
private
|
131
131
|
|
132
|
-
def export_parallel(path, key, start_time = 0, &block)
|
132
|
+
def export_parallel(path, key, start_time = 0, dedup = true, paging = true, &block)
|
133
133
|
per_page = 100 # 100 is maximum https://developer.zendesk.com/rest_api/docs/core/introduction#pagination
|
134
134
|
first_response = request(path, false, per_page: per_page, page: 1)
|
135
135
|
first_fetched = JSON.parse(first_response.body)
|
136
136
|
total_count = first_fetched["count"]
|
137
137
|
last_page_num = (total_count / per_page.to_f).ceil
|
138
|
-
Embulk.logger.info "#{key} records=#{total_count} last_page=#{last_page_num}"
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
138
|
+
Embulk.logger.info "#{key} records=#{total_count} last_page=#{paging ? last_page_num : 1}"
|
139
|
+
|
140
|
+
handler = lambda { |records| records.each { |r| block.call r } }
|
141
|
+
handler.call(dedup ? first_fetched[key].uniq { |r| r['id'] } : first_fetched[key])
|
142
|
+
|
143
|
+
# stop if endpoints have no pagination, ie. API returns all records
|
144
|
+
# `ticket_fields`, `ticket_forms`
|
145
|
+
if paging
|
146
|
+
execute_thread_pool do |pool|
|
147
|
+
(2..last_page_num).each do |page|
|
148
|
+
pool.post do
|
149
|
+
response = request(path, false, per_page: per_page, page: page)
|
150
|
+
fetched_records = extract_records_from_response(response, key)
|
151
|
+
Embulk.logger.info "Fetched #{key} on page=#{page} >>> size: #{fetched_records.length}"
|
152
|
+
handler.call(dedup ? fetched_records.uniq { |r| r['id'] } : fetched_records)
|
152
153
|
end
|
153
154
|
end
|
154
155
|
end
|
@@ -107,8 +107,7 @@ module Embulk
|
|
107
107
|
"",
|
108
108
|
{
|
109
109
|
ticket_metrics: records,
|
110
|
-
next_page: "https://treasuredata.zendesk.com/api/v2/incremental/tickets
|
111
|
-
.json?include=metric_sets&start_time=1488535542",
|
110
|
+
next_page: "https://treasuredata.zendesk.com/api/v2/incremental/tickets.json?include=metric_sets&start_time=1488535542",
|
112
111
|
}.to_json
|
113
112
|
].join("\r\n")
|
114
113
|
|
@@ -299,7 +298,7 @@ module Embulk
|
|
299
298
|
|
300
299
|
test "invoke export when partial=false" do
|
301
300
|
# Added default `start_time`
|
302
|
-
mock(client).export_parallel(anything, "ticket_fields", 0)
|
301
|
+
mock(client).export_parallel(anything, "ticket_fields", 0, true, false) # new args: `dedup`, `paging`
|
303
302
|
client.ticket_fields(false)
|
304
303
|
end
|
305
304
|
end
|
@@ -312,10 +311,40 @@ module Embulk
|
|
312
311
|
|
313
312
|
test "invoke export when partial=false" do
|
314
313
|
# Added default `start_time`
|
315
|
-
mock(client).export_parallel(anything, "ticket_forms", 0)
|
314
|
+
mock(client).export_parallel(anything, "ticket_forms", 0, true, false) # new args: `dedup`, `paging`)
|
316
315
|
client.ticket_forms(false)
|
317
316
|
end
|
318
317
|
end
|
318
|
+
|
319
|
+
sub_test_case "no pagination" do
|
320
|
+
data("ticket_fields", "ticket_fields")
|
321
|
+
data("ticket_forms", "ticket_forms")
|
322
|
+
test "non-incremental targets" do |target|
|
323
|
+
response = [
|
324
|
+
"HTTP/1.1 200",
|
325
|
+
"Content-Type: application/json",
|
326
|
+
"",
|
327
|
+
{
|
328
|
+
target => 200.times.map{|n| {"id" => n}},
|
329
|
+
count: 200,
|
330
|
+
next_page: nil,
|
331
|
+
previous_page: nil,
|
332
|
+
}.to_json
|
333
|
+
].join("\r\n")
|
334
|
+
|
335
|
+
# mock multiple responses, to simulate real API behavior
|
336
|
+
@httpclient.test_loopback_http_response << response
|
337
|
+
@httpclient.test_loopback_http_response << response
|
338
|
+
counter = Concurrent::AtomicFixnum.new(0)
|
339
|
+
handler = proc { counter.increment }
|
340
|
+
# validate expected target
|
341
|
+
proxy(@httpclient).get("#{login_url}/api/v2/#{target}.json",anything,anything)
|
342
|
+
# (`partial`, `start_time`, `default`, `block`)
|
343
|
+
client.public_send(target, false, 0, true, &handler)
|
344
|
+
# only ingest 200 records
|
345
|
+
assert_equal(200, counter.value)
|
346
|
+
end
|
347
|
+
end
|
319
348
|
end
|
320
349
|
|
321
350
|
|
@@ -629,12 +658,12 @@ module Embulk
|
|
629
658
|
"Content-Type: application/json",
|
630
659
|
"",
|
631
660
|
{
|
632
|
-
|
661
|
+
tickets: [{ id: 1 }],
|
633
662
|
count: 1
|
634
663
|
}.to_json
|
635
664
|
].join("\r\n")
|
636
665
|
handler = proc { }
|
637
|
-
client.
|
666
|
+
client.tickets(false, &handler)
|
638
667
|
assert_equal(true, @pool.shutdown?)
|
639
668
|
end
|
640
669
|
|
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.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- uu59
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-01-
|
13
|
+
date: 2019-01-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
261
|
version: '0'
|
262
262
|
requirements: []
|
263
263
|
rubyforge_project:
|
264
|
-
rubygems_version: 2.6.
|
264
|
+
rubygems_version: 2.6.14.1
|
265
265
|
signing_key:
|
266
266
|
specification_version: 4
|
267
267
|
summary: Zendesk input plugin for Embulk
|