Module: Laters::Concern
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Callbacks
- Defined in:
- lib/laters/concern.rb
Overview
Main concern that provides asynchronous execution of ActiveRecord model methods
This module adds the ability to defer execution of an instance method to a background job by calling a method with the ‘_later` suffix.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ ActiveJob::Base (private)
Handles method calls with _later suffix by enqueueing background jobs
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/laters/concern.rb', line 66 def method_missing(method, *args, **kwargs, &block) if (method_to_call = deferrable_method_name(method)) # Extract ActiveJob options if they exist in kwargs = { queue: self.class.job_queue || :default } # Move scheduling options from kwargs to job_options [:wait] = kwargs.delete(:wait) if kwargs.key?(:wait) [:wait_until] = kwargs.delete(:wait_until) if kwargs.key?(:wait_until) [:priority] = kwargs.delete(:priority) if kwargs.key?(:priority) # Set all options at once InstanceMethodJob .set() .perform_later(self, method_to_call, *args, **kwargs) else super end end |