module Aservice::ClassMethods
Class methods for service.
Public Instance Methods
call_after(jid, *args)
click to toggle source
# File lib/aservice.rb, line 26 def call_after(jid, *args) args = [] if args.nil? perform(:after, 'call', args.unshift(jid)) end
call_async(*args)
click to toggle source
# File lib/aservice.rb, line 22 def call_async(*args) perform(:async, 'call', args) end
method_missing(method, *args)
click to toggle source
# File lib/aservice.rb, line 35 def method_missing(method, *args) method = method.to_s if method =~ /_async$/ method = method.sub(/.*\K_async/, '') perform(:async, method, args) elsif method =~ /_after$/ method = method.sub(/.*\K_after/, '') perform(:after, method, args) else raise_no_method_error("No method: #{method} for class: #{AserviceWorker.name}") end end
respond_to_missing?(method, _)
click to toggle source
# File lib/aservice.rb, line 31 def respond_to_missing?(method, _) return false if method =~ /_(async|after)$/ end
Private Instance Methods
perform(type, method, args)
click to toggle source
# File lib/aservice.rb, line 50 def perform(type, method, args) worker = AserviceWorker.set(queue: Aservice::Config.queue) raise_no_method_error("No method: #{method} for class: #{name}") unless respond_to?(method.to_sym) return worker.perform_async(name, method, *args) if type == :async jid = args.shift if Sidekiq::Status.complete?(jid) worker.perform_async(name, method, *args) else worker.perform_after(jid, name, method, *args) end end
raise_no_method_error(msg)
click to toggle source
# File lib/aservice.rb, line 63 def raise_no_method_error(msg) raise NoMethodError, msg end