Sha256: 0b8d6855b0e575ada0de1fc948250a0d56851969b2ede542ed6f998df12573d7

Contents?: true

Size: 1.34 KB

Versions: 22

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "active_support/rescuable"
require "active_job/arguments"

module ActiveJob
  module Execution
    extend ActiveSupport::Concern
    include ActiveSupport::Rescuable

    # Includes methods for executing and performing jobs instantly.
    module ClassMethods
      # Performs the job immediately.
      #
      #   MyJob.perform_now("mike")
      #
      def perform_now(*args)
        job_or_instantiate(*args).perform_now
      end
      ruby2_keywords(:perform_now) if respond_to?(:ruby2_keywords, true)

      def execute(job_data) #:nodoc:
        ActiveJob::Callbacks.run_callbacks(:execute) do
          job = deserialize(job_data)
          job.perform_now
        end
      end
    end

    # Performs the job immediately. The job is not sent to the queuing adapter
    # but directly executed by blocking the execution of others until it's finished.
    #
    #   MyJob.new(*args).perform_now
    def perform_now
      # Guard against jobs that were persisted before we started counting executions by zeroing out nil counters
      self.executions = (executions || 0) + 1

      deserialize_arguments_if_needed
      run_callbacks :perform do
        perform(*arguments)
      end
    rescue => exception
      rescue_with_handler(exception) || raise
    end

    def perform(*)
      fail NotImplementedError
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
activejob-6.0.6.1 lib/active_job/execution.rb
activejob-6.0.6 lib/active_job/execution.rb
activejob-6.0.5.1 lib/active_job/execution.rb
activejob-6.0.5 lib/active_job/execution.rb
activejob-6.0.4.8 lib/active_job/execution.rb
activejob-6.0.4.7 lib/active_job/execution.rb
activejob-6.0.4.6 lib/active_job/execution.rb
activejob-6.0.4.5 lib/active_job/execution.rb
activejob-6.0.4.4 lib/active_job/execution.rb
activejob-6.0.4.3 lib/active_job/execution.rb
activejob-6.0.4.2 lib/active_job/execution.rb
activejob-6.0.4.1 lib/active_job/execution.rb
activejob-6.0.4 lib/active_job/execution.rb
activejob-6.0.3.7 lib/active_job/execution.rb
activejob-6.0.3.6 lib/active_job/execution.rb
activejob-6.0.3.5 lib/active_job/execution.rb
activejob-6.0.3.4 lib/active_job/execution.rb
activejob-6.0.3.3 lib/active_job/execution.rb
activejob-6.0.3.2 lib/active_job/execution.rb
activejob-6.0.3.1 lib/active_job/execution.rb