Sha256: 23bffd68047ad21dad9228cc83b7d9ce8908ac3dced592ffbd16ac26592fc061

Contents?: true

Size: 1.55 KB

Versions: 18

Compression:

Stored size: 1.55 KB

Contents

# this forces loading of glue.rb and its methods
# otherwise we end up with an empty Glue module
# when caching of classes is Rails is on
#
# PLEASE DO NOT REMOVE WITHOUT TESTING WITH
# config.cache_classes = true
#
require "katello/glue"

# represents tasks queue for glue
module Katello
  module Glue
    class Queue
      attr_reader :items
      STATUS = %w(pending running failed completed rollbacked)

      # we can put more queues sequentially. E.g. on queue before saving a record,
      # another after saving. If something in later queue fails we roll-back also
      # everything in previous queues.
      def initialize(previous_queue = nil)
        @previous_queue = previous_queue
        @items          = []
      end

      def create(options)
        options[:status] ||= default_status
        Glue::Task.new(options).tap { |t| items << t }
      end

      def delete(item)
        @items.delete item
      end

      def find_by_name(name)
        items.each { |task| return task if task.name == name }
      end

      def all
        ret = []
        ret.concat(@previous_queue.all) if @previous_queue
        ret.concat(items.sort)
        ret
      end

      delegate :count, :to => :items
      delegate :empty?, :to => :items

      def clear
        @items = [] && true
      end

      def to_log
        all.collect(&:to_log).join ", "
      end

      STATUS.each do |s|
        define_method s do
          all.find_all { |t| t.status == s }
        end
      end

      private

      def default_status
        "pending"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
katello-3.0.2 app/lib/katello/glue/queue.rb
katello-2.4.5 app/lib/katello/glue/queue.rb
katello-3.0.1 app/lib/katello/glue/queue.rb
katello-2.4.4 app/lib/katello/glue/queue.rb
katello-3.0.0 app/lib/katello/glue/queue.rb
katello-2.4.3 app/lib/katello/glue/queue.rb
katello-3.0.0.rc7 app/lib/katello/glue/queue.rb
katello-3.0.0.rc5 app/lib/katello/glue/queue.rb
katello-2.4.2 app/lib/katello/glue/queue.rb
katello-3.0.0.rc4 app/lib/katello/glue/queue.rb
katello-3.0.0.rc3 app/lib/katello/glue/queue.rb
katello-3.0.0.rc2 app/lib/katello/glue/queue.rb
katello-3.0.0.rc1 app/lib/katello/glue/queue.rb
katello-2.4.1 app/lib/katello/glue/queue.rb
katello-2.4.0 app/lib/katello/glue/queue.rb
katello-2.4.0.rc3 app/lib/katello/glue/queue.rb
katello-2.4.0.rc2 app/lib/katello/glue/queue.rb
katello-2.4.0.rc1 app/lib/katello/glue/queue.rb