Sha256: 37e83b0767de461eb39dbadbfde60fb2e5bfd3ffd05e9b491d68fe9beb643d71

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

module Patriot
  module Command
    module PostProcessor
      class Retrial < Patriot::Command::PostProcessor::Base

        COUNT_PROP_KEY    = :count
        INTERVAL_PROP_KEY = :interval

        declare_post_processor_name :retrial

        def validate_props(props)
          raise "#{COUNT_PROP_KEY} is not specified" unless props.has_key?(COUNT_PROP_KEY)
          raise "#{INTERVAL_PROP_KEY} is not specified" unless props.has_key?(INTERVAL_PROP_KEY)
        end

        def process_failure(cmd, worker, job_ticket)
          found = false
          cmd.post_processors.each do |pp|
            next unless pp.is_a?(Patriot::Command::PostProcessor::Retrial)
            raise "multiple retry processors in #{cmd.job_id}" if found
            found = true
            # count first attempt in
            pp.props[COUNT_PROP_KEY] = pp.props[COUNT_PROP_KEY] - 1
            return true if pp.props[COUNT_PROP_KEY] < 1
            cmd.start_datetime = Time.now + pp.props[INTERVAL_PROP_KEY]
          end
          job = cmd.to_job
          current_config = worker.job_store.get_job(job.job_id)
          job[Patriot::Command::PRODUCTS_ATTR] = current_config[Patriot::Command::PRODUCTS_ATTR]
          job[Patriot::Command::REQUISITES_ATTR] = current_config[Patriot::Command::REQUISITES_ATTR]
          job[Patriot::Command::STATE_ATTR] = Patriot::JobStore::JobState::WAIT
          worker.job_store.register(Time.now.to_i, [job])
          return false
        end

      end
    end
  end
end


Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
patriot-workflow-scheduler-0.8.8 lib/patriot/command/post_processor/retrial.rb
patriot-workflow-scheduler-0.8.7 lib/patriot/command/post_processor/retrial.rb
patriot-workflow-scheduler-0.8.6 lib/patriot/command/post_processor/retrial.rb
patriot-workflow-scheduler-0.8.5 lib/patriot/command/post_processor/retrial.rb