embulk-input-zendesk 0.1.7 → 0.1.8

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: 73115292227dc5474093e998c1025f4a0fa55c22
4
- data.tar.gz: 23cd509f73bfa2c8ccff24478b258295c32c8806
3
+ metadata.gz: eaddbf9ca58a72b5bb9e00497f7eef3c3303e171
4
+ data.tar.gz: 4a13d21ceff5b8d019f43d9c98ea4f0dac59840c
5
5
  SHA512:
6
- metadata.gz: 6364750da3c79b7dc8a8e9507887884d3cda61445ad8f775b7bffbfb764f07a49938621380060c323c43a1a806b4ffc20f1d69a3e8e045ec7c12aa0e8d1c84a3
7
- data.tar.gz: 93ae137dacd61c9b56f323916f6993a6f7b077231646227e85003c85d1966ee8b66c1ab99cf87c922ccc55f021ff5edeb8f136aad5039448a6d99fc5af98961d
6
+ metadata.gz: fe9134f35bc6d9d0a303f103c7d85ac017eb43a2c2db662c8ae7d18bac85afaed44572cefa6c6fab21ac1c5f6a35861ee61088edcac72421b2fb018844bf3e96
7
+ data.tar.gz: 3933f732fd8f073fc52f9ce44962a7e9b8ce6ba248e77d9c45cf1468093ded9f21a0092cb29e7c9b7b779bf820211388f9c0365412e10f52768cfc19dc341a7e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.8 - 2016-07-11
2
+
3
+ * [enhancement] For huge data [#13](https://github.com/treasure-data/embulk-input-zendesk/pull/13)
4
+ * [enhancement] Improvements for non incremental export [#12](https://github.com/treasure-data/embulk-input-zendesk/pull/12)
5
+
1
6
  ## 0.1.7 - 2016-06-04
2
7
  * [enhancement] Improvements for non incremental export [#12](https://github.com/treasure-data/embulk-input-zendesk/pull/12)
3
8
 
data/README.md CHANGED
@@ -30,7 +30,7 @@ Required Embulk version >= 0.8.1.
30
30
  - **access_token**: OAuth Access Token. required if `auth_method` is `oauth`. (string, default: `null`)
31
31
  - **start_time**: Start export from this time if present. (string, default: `null`)
32
32
  - **retry_limit**: Try to retry this times (integer, default: 5)
33
- - **retry_initial_wait_sec**: Wait seconds for exponential backoff initial value (integer, default: 1)
33
+ - **retry_initial_wait_sec**: Wait seconds for exponential backoff initial value (integer, default: 4)
34
34
  - **incremental**: If false, `start_time` in next.yml would not be updated that means you always fetch all of data from Zendesk with statically conditions. If true, `start_time` would be updated in next.yml. (bool, default: true)
35
35
 
36
36
  ## Example
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-input-zendesk"
4
- spec.version = "0.1.7"
4
+ spec.version = "0.1.8"
5
5
  spec.authors = ["uu59", "muga", "sakama"]
6
6
  spec.summary = "Zendesk input plugin for Embulk"
7
7
  spec.description = "Loads records from Zendesk."
@@ -20,6 +20,7 @@ module Embulk
20
20
 
21
21
  def httpclient
22
22
  httpclient = HTTPClient.new
23
+ httpclient.connect_timeout = 240 # default:60 is not enough for huge data
23
24
  # httpclient.debug_dev = STDOUT
24
25
  return set_auth(httpclient)
25
26
  end
@@ -162,35 +163,39 @@ module Embulk
162
163
  def incremental_export(path, key, start_time = 0, known_ids = [], partial = true, &block)
163
164
  if partial
164
165
  records = request_partial(path, {start_time: start_time}).first(5)
165
- else
166
+ records.uniq{|r| r["id"]}.each do |record|
167
+ block.call record
168
+ end
169
+ return
170
+ end
171
+
172
+ loop do
173
+ start_fetching = Time.now
166
174
  response = request(path, {start_time: start_time})
167
175
  begin
168
176
  data = JSON.parse(response.body)
169
177
  rescue => e
170
178
  raise Embulk::DataError.new(e)
171
179
  end
172
- Embulk.logger.info "Fetched records from #{start_time} (#{Time.at(start_time)})"
180
+ actual_fetched = 0
173
181
  records = data[key]
174
- end
175
-
176
- records.each do |record|
177
- # de-duplicated records.
178
- # https://developer.zendesk.com/rest_api/docs/core/incremental_export#usage-notes
179
- # https://github.com/zendesk/zendesk_api_client_rb/issues/251
180
- next if known_ids.include?(record["id"])
181
-
182
- known_ids << record["id"]
183
- block.call record
184
- end
185
- return if partial
182
+ records.each do |record|
183
+ # de-duplicated records.
184
+ # https://developer.zendesk.com/rest_api/docs/core/incremental_export#usage-notes
185
+ # https://github.com/zendesk/zendesk_api_client_rb/issues/251
186
+ next if known_ids.include?(record["id"])
187
+
188
+ known_ids << record["id"]
189
+ block.call record
190
+ actual_fetched += 1
191
+ end
192
+ Embulk.logger.info "Fetched #{actual_fetched} records from start_time:#{start_time} (#{Time.at(start_time)}) within #{Time.now.to_i - start_fetching.to_i} seconds"
193
+ start_time = data["end_time"]
186
194
 
187
- # NOTE: If count is less than 1000, then stop paginating.
188
- # Otherwise, use the next_page URL to get the next page of results.
189
- # https://developer.zendesk.com/rest_api/docs/core/incremental_export#pagination
190
- if data["count"] == 1000
191
- incremental_export(path, key, data["end_time"], known_ids, partial, &block)
192
- else
193
- data
195
+ # NOTE: If count is less than 1000, then stop paginating.
196
+ # Otherwise, use the next_page URL to get the next page of results.
197
+ # https://developer.zendesk.com/rest_api/docs/core/incremental_export#pagination
198
+ break data if data["count"] < 1000
194
199
  end
195
200
  end
196
201
 
@@ -375,12 +375,14 @@ module Embulk
375
375
  "Content-Type: application/json",
376
376
  "",
377
377
  {
378
- tickets: tickets
378
+ tickets: tickets,
379
+ count: tickets.length,
379
380
  }.to_json
380
381
  ].join("\r\n")
381
382
 
382
383
  tickets.each do |ticket|
383
- mock(page_builder).add([ticket["id"]])
384
+ # schema[:columns] is id and tags. tags should be nil
385
+ mock(page_builder).add([ticket["id"], nil])
384
386
  end
385
387
  mock(page_builder).finish
386
388
 
@@ -413,6 +415,7 @@ module Embulk
413
415
  {
414
416
  ticket_events: events,
415
417
  end_time: end_time,
418
+ count: events.length,
416
419
  }.to_json
417
420
  ].join("\r\n")
418
421
  stub(page_builder).add(anything)
@@ -452,7 +455,8 @@ module Embulk
452
455
  "Content-Type: application/json",
453
456
  "",
454
457
  {
455
- tickets: data
458
+ tickets: data,
459
+ count: data.length,
456
460
  }.to_json
457
461
  ].join("\r\n")
458
462
  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.1.7
4
+ version: 0.1.8
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: 2016-06-03 00:00:00.000000000 Z
13
+ date: 2016-07-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  requirement: !ruby/object:Gem::Requirement