Sha256: 8d2d9a707a4e9c41b2597cba4e011ad7a0dcf5b39601953750fcd0c003681649

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

if defined?(::ActiveJob)
  module Lev
    module ActiveJob
      class Base < ::ActiveJob::Base
        def self.perform_later(routine_class, *args, &block)
          queue_as routine_class.active_job_queue
          args.push(routine_class.to_s)

          # To enable tracking of this job's status, create a new BackgroundJob object
          # and push it on to the arguments so that in `perform` it can be peeled
          # off and handed to the routine instance.  The BackgroundJob UUID is returned
          # so that callers can track the status.
          job = Lev::BackgroundJob.new
          job.queued!
          args.push(job.id)

          super(*args, &block)

          job.id
        end

        def perform(*args, &block)
          # Pop arguments added by perform_later
          id = args.pop
          routine_class = Kernel.const_get(args.pop)

          routine_instance = routine_class.new(Lev::BackgroundJob.new(id: id))
          routine_instance.call(*args, &block)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lev-6.0.0 lib/lev/active_job.rb
lev-5.0.0 lib/lev/active_job.rb