lib/embulk/input/zendesk/plugin.rb in embulk-input-zendesk-0.1.13 vs lib/embulk/input/zendesk/plugin.rb in embulk-input-zendesk-0.2.6
- old
+ new
@@ -1,6 +1,6 @@
-require "perfect_retry"
+require 'perfect_retry'
module Embulk
module Input
module Zendesk
class Plugin < InputPlugin
@@ -108,15 +108,18 @@
args = [preview?]
if @start_time
args << @start_time.to_i
end
+ mutex = Mutex.new
fetching_start_at = Time.now
last_data = client.public_send(method, *args) do |record|
record = fetch_related_object(record)
values = extract_values(record)
- page_builder.add(values)
+ mutex.synchronize do
+ page_builder.add(values)
+ end
break if preview? # NOTE: preview take care only 1 record. subresources fetching is slow.
end
page_builder.finish
task_report = {}
@@ -131,17 +134,18 @@
# Sometimes no record and no end_time fetched on the job, but we should generate start_time on config_diff.
task_report[:start_time] = fetching_start_at
end
end
- return task_report
+ task_report
end
private
def fetch_related_object(record)
- (task[:includes] || []).each do |ent|
- record[ent] = client.fetch_subresource(record["id"], task[:target], ent)
+ return record unless task[:includes] && !task[:includes].empty?
+ task[:includes].each do |ent|
+ record[ent] = client.fetch_subresource(record['id'], task[:target], ent)
end
record
end
def client