module Resque::Plugins::Stages
This module is added to any job class which needs to work within a stage.
If the job is going to be retryable, this module needs to be included after the retry module is extended so that we know that the class is retryable.
Constants
- VERSION
Public Instance Methods
add_record_failure()
click to toggle source
# File lib/resque/plugins/stages.rb, line 99 def add_record_failure define_singleton_method(:on_failure_stages_failed) do |_error, *args| job = perform_job(*args) return if job.blank? job.status = :failed end end
after_perform_stages_successful(*args)
click to toggle source
# File lib/resque/plugins/stages.rb, line 63 def after_perform_stages_successful(*args) job = perform_job(*args) return if job.blank? return if job.status == :failed && Resque.inline? job.status = :successful end
around_perform_stages_inline_around(*args) { || ... }
click to toggle source
# File lib/resque/plugins/stages.rb, line 72 def around_perform_stages_inline_around(*args) yield rescue StandardError => e raise e unless Resque.inline? job = perform_job(*args) return if job.blank? job.status = :failed end
before_perform_stages_successful(*args)
click to toggle source
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/AbcSize
# File lib/resque/plugins/stages.rb, line 55 def before_perform_stages_successful(*args) job = perform_job(*args) return if job.blank? job.status = :running end
perform_job(*args)
click to toggle source
# File lib/resque/plugins/stages.rb, line 25 def perform_job(*args) job = perform_job_from_param(args) if job.nil? job = Resque::Plugins::Stages::StagedJob.new(SecureRandom.uuid) job.class_name = name job.args = args end job = perform_job(*job.uncompressed_args) if job.compressed? job end
perform_job_from_param(args)
click to toggle source
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity
# File lib/resque/plugins/stages.rb, line 41 def perform_job_from_param(args) return if args.blank? || !args.first.is_a?(Hash) hash = args.first.with_indifferent_access job = Resque::Plugins::Stages::StagedJob.new(hash[:staged_job_id]) if hash.key?(:staged_job_id) job&.class_name = name job.args = (hash.key?(:resque_compressed) ? args : args[1..]) if !job.nil? && job.blank? job end
stages_report_giving_up(_exception, *args)
click to toggle source
# File lib/resque/plugins/stages.rb, line 91 def stages_report_giving_up(_exception, *args) job = perform_job(*args) return if job.blank? job.status = :failed end
stages_report_try_again(_exception, *args)
click to toggle source
# File lib/resque/plugins/stages.rb, line 83 def stages_report_try_again(_exception, *args) job = perform_job(*args) return if job.blank? job.status = :pending_re_run end