Sha256: 01722ad4de45c4feaf921b9c7da4a8781294f00b31a0036d59997a44a7fe6e0b

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

require 'active_support/concern'

begin
  require 'sidekiq'
  require 'sidekiq/api'
rescue LoadError
  raise Services::BackgroundProcessorNotFound
end

module Services
  module Asyncable
    extend ActiveSupport::Concern

    ASYNC_METHOD_SUFFIXES = %i(async in at).freeze

    included do
      include Sidekiq::Worker
    end

    module ClassMethods
      ASYNC_METHOD_SUFFIXES.each do |async_method_suffix|
        define_method "call_#{async_method_suffix}" do |*args|
          args.map! do |arg|
            arg.respond_to?(:to_global_id) ? arg.to_global_id : arg
          end
          self.public_send "perform_#{async_method_suffix}", *args
        end
      end
    end

    def perform(*args)
      args.map! do |arg|
        GlobalID::Locator.locate(arg) || arg
      end
      call *args
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
services-6.0.0 lib/services/asyncable.rb