Sha256: 9bb3d9cc34113512b0def65e059051121df2873ab58789a880be7c09211797f8

Contents?: true

Size: 1.32 KB

Versions: 56

Compression:

Stored size: 1.32 KB

Contents

# require "eitil_wrapper/jobs/new_job_now"

require "eitil_wrapper/jobs/single_method_job"

# BEWARE: This is an exact copy of the .new_job method, except for .perform_now instead of .perform_later and the method's name.
# The reason for not using helper methods is to not unnecessarily fill and potentially fuck up the Kernel environment.

Kernel.module_eval do

  # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors

  # The cases of 'id' and '_self' both handle instances, with the difference 
  # being that 'id' works for objects that have a database record, while '_self'
  # works for non database supported instanes, such as an Exporter instance.

  def new_job_now(_method, *args, **kwargs)

    if instance_methods(false).include? _method
      define_method "#{_method}_job_now" do |_self = nil, *args, **kwargs|
        
        EitilWrapper::SingleMethodJob.perform_now(
          *args, _class: self.class.to_s, _method: _method.to_s, id: safe_send(:id), _self: self.to_json, **kwargs
        )
      end

    elsif singleton_methods(false).include? _method      
      define_singleton_method "#{_method}_job_now" do |*args, **kwargs|
       
        EitilWrapper::SingleMethodJob.perform_now(
          *args, _class: to_s, _method: _method.to_s, **kwargs
        )
      end
    end 
  end

end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
eitil-1.1.22 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.21 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.20 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.19 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.18 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.17 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.16 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.15 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.14 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.13 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.12 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.11 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.10 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.9 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.8 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb
eitil-1.1.7 eitil_wrapper/lib/eitil_wrapper/jobs/new_job_now.rb