Sha256: 4edfcb371e8aefcf441f5a2efe4ea888f8a0703a2ca403017623ade7aa846d78

Contents?: true

Size: 998 Bytes

Versions: 5

Compression:

Stored size: 998 Bytes

Contents

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
qujo-0.1.4 lib/qujo/concerns/model.rb
qujo-0.1.3 lib/qujo/concerns/model.rb
qujo-0.1.2 lib/qujo/concerns/model.rb
qujo-0.1.1 lib/qujo/concerns/model.rb
qujo-0.1.0 lib/qujo/concerns/model.rb