module Qujo module Concerns module Model extend ActiveSupport::Concern included do def enqueue(action, options={}) name = options[:job] || "#{Qujo.config.models}::#{self.class.name.capitalize}::#{action.capitalize}" raise Qujo::Exceptions::JobNameUndefined unless name begin klass = name.constantize rescue => e raise Qujo::Exceptions::JobNameUndefined, e.message end data = {} data = data.merge(model: {id: self.id.to_s, class: self.class.name}) parent = options.delete(:parent) if parent && parent.is_a?(::Job) data = data.merge(parent: {id: parent.id.to_s, class: parent.class.name}) end data = data.merge(options) job = klass.create(data: data) logger.info "** ENQUEUE: JOB=#{j.id} NAME=#{n} DATA=#{d}" if self.respond_to?(:logger) job.enqueue end end end end end