class Lev::ActiveJob::Base
Attributes
provider_job_id[RW]
Public Instance Methods
perform(*args, &block)
click to toggle source
# File lib/lev/active_job/base.rb, line 38 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(routine_class.find_status(id)) routine_instance.call(*args, &block) end
perform_later(routine_class, options, *args, &block)
click to toggle source
# File lib/lev/active_job/base.rb, line 6 def perform_later(routine_class, options, *args, &block) # Create a new status object status = routine_class.create_status # Push the routine class name on to the arguments # so that we can run the correct routine in `perform` args.push(routine_class.to_s) # Push the status's ID on to the arguments so that in `perform` # it can be used to retrieve the status when the routine is initialized args.push(status.id) # Set the job_name status.set_job_name(routine_class.name) # In theory we'd mark as queued right after the call to super, but this messes # up when the activejob adapter runs the job right away (inline mode) status.queued! # Queue up the job and set the provider_job_id # For delayed_job, requires either Rails 5 or # http://stackoverflow.com/questions/29855768/rails-4-2-get-delayed-job-id-from-active-job provider_job_id = self.class.send(:job_or_instantiate, *args, &block) .enqueue(options) .provider_job_id status.set_provider_job_id(provider_job_id) \ if provider_job_id.present? && status.respond_to?(:set_provider_job_id) # Return the id of the status object status.id end