Sha256: 5650aaa88372f3c17216b833d69bb737fb56aec65327772417ab2052819b5d76

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

module JobNotifier
  module Notifier
    extend ActiveSupport::Concern

    included do
      def perform(*args)
        result = perform_with_feedback(*args)
        save_success_feedback(result)
      rescue JobNotifier::Error::Validation => ex
        save_error_feedback(ex.error)
      rescue StandardError => ex
        save_error_feedback("unknown")
        raise ex
      end

      def save_error_feedback(error)
        JobNotifier::Job.update_feedback(job_id, error, :failed)
      end

      def save_success_feedback(data)
        JobNotifier::Job.update_feedback(job_id, data, :finished)
      end

      before_enqueue do |job|
        if job.respond_to?(:perform_with_feedback)
          identifier = job.arguments.shift
          raise JobNotifier::Error::InvalidIdentifier.new if identifier.blank?

          JobNotifier::Job.create!(
            identifier: identifier,
            job_id: job.job_id,
            job_class: self.class.name
          )
        end
      end
    end
  end
end

ActiveJob::Base.send(:include, JobNotifier::Notifier)

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
job_notifier-1.4.0 lib/job_notifier/notifier.rb
job_notifier-1.3.0 lib/job_notifier/notifier.rb
job_notifier-1.2.4 lib/job_notifier/notifier.rb
job_notifier-1.2.3 lib/job_notifier/notifier.rb
job_notifier-1.2.2 lib/job_notifier/notifier.rb
job_notifier-1.2.1 lib/job_notifier/notifier.rb
job_notifier-1.2.0 lib/job_notifier/notifier.rb
job_notifier-1.1.1 lib/job_notifier/notifier.rb
job_notifier-1.1.0 lib/job_notifier/notifier.rb
job_notifier-1.0.0 lib/job_notifier/notifier.rb
job_notifier-0.2.1 lib/job_notifier/notifier.rb
job_notifier-0.2.0 lib/job_notifier/notifier.rb