lib/embulk/input/zendesk/plugin.rb in embulk-input-zendesk-0.1.12 vs lib/embulk/input/zendesk/plugin.rb in embulk-input-zendesk-0.1.13

- old
+ new

@@ -108,24 +108,30 @@ args = [preview?] if @start_time args << @start_time.to_i end + 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) break if preview? # NOTE: preview take care only 1 record. subresources fetching is slow. end page_builder.finish task_report = {} - if task[:incremental] && last_data && last_data["end_time"] - # NOTE: start_time compared as "=>", not ">". - # If we will use end_time for next start_time, we got the same record that is last fetched - # end_time + 1 is workaround for that - next_start_time = Time.at(last_data["end_time"] + 1) - task_report[:start_time] = next_start_time.strftime("%Y-%m-%d %H:%M:%S%z") + if task[:incremental] + if last_data && last_data["end_time"] + # NOTE: start_time compared as "=>", not ">". + # If we will use end_time for next start_time, we got the same record that is last fetched + # end_time + 1 is workaround for that + next_start_time = Time.at(last_data["end_time"] + 1) + task_report[:start_time] = next_start_time.strftime("%Y-%m-%d %H:%M:%S%z") + else + # 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 end