Sha256: cba7eab00be37c31b7eccceea37826337f87d5ddb810a5b1d24306d0de42e735
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
require "active_support/core_ext/class/subclasses" require "active_job" module Maitredee module ActiveJob def self.extended(mod) mod.descendants.each do |klass| create_publisher_job(klass) end end def self.create_publisher_job(subclass) subclass.const_set("PublisherJob", Class.new(BasePublisherJob)) subclass::PublisherJob.service_class = subclass end # Uses ActieJob to async the publishing # @example To configure the specific async job open PublisherJob # class RecipePublisher < Maitredee::Publisher # class PublisherJob # queue_as :low # end # end # # RecipePublisher.call_later(Recipe.find(1)) # def call_later(*args) self::PublisherJob.perform_later(*args) end private def inherited(subclass) create_publisher_job(subclass) super end def create_publisher_job(subclass) Maitredee::ActiveJob.create_publisher_job(subclass) end class BasePublisherJob < ::ActiveJob::Base class << self attr_accessor :service_class end def perform(*args) self.class.service_class.call(*args) end end ::Maitredee::Publisher.extend(self) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
maitredee-0.8.3 | lib/maitredee/active_job.rb |