lib/embulk/input/jira.rb in embulk-input-jira-0.0.7 vs lib/embulk/input/jira.rb in embulk-input-jira-0.1.0

- old
+ new

@@ -1,5 +1,6 @@ +require "perfect_retry" require "embulk/input/jira_input_plugin_utils" require "embulk/input/jira_api" module Embulk module Input @@ -25,10 +26,12 @@ attributes[name] = type Column.new(nil, name, type, column["format"]) end task[:attributes] = attributes + task[:retry_limit] = config.param(:retry_limit, :integer, default: 5) + task[:retry_initial_wait_sec] = config.param(:retry_initial_wait_sec, :integer, default: 1) resume(task, columns, 1, &control) end def self.resume(task, columns, count, &control) @@ -77,25 +80,31 @@ config.uri = task[:uri] config.api_version = "latest" config.auth_type = "basic" end @jql = task[:jql] + @retryer = PerfectRetry.new do |config| + config.limit = task[:retry_limit] + config.sleep = proc{|n| task[:retry_initial_wait_sec] ** n} + config.dont_rescues = [Embulk::ConfigError] + end end def run return preview if preview? options = {} total_count = @jira.total_count(@jql) last_page = (total_count.to_f / PER_PAGE).ceil 0.step(total_count, PER_PAGE).with_index(1) do |start_at, page| logger.debug "Fetching #{page} / #{last_page} page" - @jira.search_issues(@jql, options.merge(start_at: start_at)).each do |issue| - values = @attributes.map do |(attribute_name, type)| - JiraInputPluginUtils.cast(issue[attribute_name], type) + @retryer.with_retry do + @jira.search_issues(@jql, options.merge(start_at: start_at)).each do |issue| + values = @attributes.map do |(attribute_name, type)| + JiraInputPluginUtils.cast(issue[attribute_name], type) + end + page_builder.add(values) end - - page_builder.add(values) end end page_builder.finish