queueing_rabbit 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/queueing_rabbit/extensions/direct_exchange.rb +1 -1
- data/lib/queueing_rabbit/job.rb +65 -16
- data/lib/queueing_rabbit/tasks.rb +1 -1
- data/lib/queueing_rabbit/version.rb +1 -1
- data/spec/integration/configuration_spec.rb +75 -0
- data/spec/integration/persistent_asynchronous_publishing_and_consuming_spec.rb +1 -1
- data/spec/unit/queueing_rabbit/job_spec.rb +0 -1
- data/spec/unit/queueing_rabbit/jobs/abstract_job_spec.rb +0 -1
- metadata +6 -4
    
        data/lib/queueing_rabbit/job.rb
    CHANGED
    
    | @@ -1,50 +1,92 @@ | |
| 1 1 | 
             
            module QueueingRabbit
         | 
| 2 | 
            +
              module InheritableClassVariables
         | 
| 3 | 
            +
                def inheritable_variables(*args)
         | 
| 4 | 
            +
                  @inheritable_variables ||= [:inheritable_variables]
         | 
| 5 | 
            +
                  @inheritable_variables += args
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def inherited(subclass)
         | 
| 9 | 
            +
                  @inheritable_variables ||= []
         | 
| 10 | 
            +
                  @inheritable_variables.each do |var|
         | 
| 11 | 
            +
                    if !subclass.instance_variable_get("@#{var}") ||
         | 
| 12 | 
            +
                       subclass.instance_variable_get("@#{var}").empty?
         | 
| 13 | 
            +
                      subclass.instance_variable_set("@#{var}",
         | 
| 14 | 
            +
                                                     instance_variable_get("@#{var}"))
         | 
| 15 | 
            +
                    end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 2 19 |  | 
| 3 20 | 
             
              module Job
         | 
| 21 | 
            +
                def self.extended(othermod)
         | 
| 22 | 
            +
                  othermod.extend(QueueingRabbit::InheritableClassVariables)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  othermod.class_eval do
         | 
| 25 | 
            +
                    inheritable_variables :queue_name, :queue_options, :channel_options,
         | 
| 26 | 
            +
                                          :exchange_name, :exchange_options,
         | 
| 27 | 
            +
                                          :binding_options, :listening_options,
         | 
| 28 | 
            +
                                          :publishing_defaults
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                end
         | 
| 4 31 |  | 
| 5 32 | 
             
                def queue(*args)
         | 
| 33 | 
            +
                  @queue_options ||= {}
         | 
| 6 34 | 
             
                  if args.first.kind_of?(Hash)
         | 
| 7 | 
            -
                    @queue_options | 
| 35 | 
            +
                    @queue_options.update(args.first)
         | 
| 36 | 
            +
                  elsif args.count > 1
         | 
| 37 | 
            +
                    name, options = args
         | 
| 38 | 
            +
                    @queue_name = name
         | 
| 39 | 
            +
                    @queue_options.update(options)
         | 
| 8 40 | 
             
                  else
         | 
| 9 | 
            -
                    @queue_name | 
| 41 | 
            +
                    @queue_name = args.first
         | 
| 10 42 | 
             
                  end
         | 
| 11 43 | 
             
                end
         | 
| 12 44 |  | 
| 13 45 | 
             
                def queue_name
         | 
| 14 | 
            -
                  @queue_name  | 
| 46 | 
            +
                  @queue_name || (self.name.split('::')[-1] if self.name)
         | 
| 15 47 | 
             
                end
         | 
| 16 48 |  | 
| 17 49 | 
             
                def queue_options
         | 
| 18 | 
            -
                  @queue_options  | 
| 50 | 
            +
                  @queue_options || {}
         | 
| 19 51 | 
             
                end
         | 
| 20 52 |  | 
| 21 53 | 
             
                def queue_size
         | 
| 22 54 | 
             
                  QueueingRabbit.queue_size(self)
         | 
| 23 55 | 
             
                end
         | 
| 24 56 |  | 
| 25 | 
            -
                def channel(options={})
         | 
| 26 | 
            -
                  @channel_options  | 
| 57 | 
            +
                def channel(options = {})
         | 
| 58 | 
            +
                  @channel_options ||= {}
         | 
| 59 | 
            +
                  @channel_options.update(options)
         | 
| 27 60 | 
             
                end
         | 
| 28 61 |  | 
| 29 62 | 
             
                def channel_options
         | 
| 30 63 | 
             
                  @channel_options ||= {}
         | 
| 31 64 | 
             
                end
         | 
| 32 65 |  | 
| 33 | 
            -
                def exchange( | 
| 34 | 
            -
                  @ | 
| 35 | 
            -
                   | 
| 66 | 
            +
                def exchange(*args)
         | 
| 67 | 
            +
                  @exchange_options ||= {}
         | 
| 68 | 
            +
                  if args.first.kind_of?(Hash)
         | 
| 69 | 
            +
                    @exchange_options.update(args.first)
         | 
| 70 | 
            +
                  elsif args.count > 1
         | 
| 71 | 
            +
                    name, options = args
         | 
| 72 | 
            +
                    @exchange_name = name
         | 
| 73 | 
            +
                    @exchange_options.update(options)
         | 
| 74 | 
            +
                  else
         | 
| 75 | 
            +
                    @exchange_name = args.first
         | 
| 76 | 
            +
                  end
         | 
| 36 77 | 
             
                end
         | 
| 37 78 |  | 
| 38 79 | 
             
                def exchange_name
         | 
| 39 | 
            -
                  @exchange_name
         | 
| 80 | 
            +
                  @exchange_name || ''
         | 
| 40 81 | 
             
                end
         | 
| 41 82 |  | 
| 42 83 | 
             
                def exchange_options
         | 
| 43 | 
            -
                  @exchange_options  | 
| 84 | 
            +
                  @exchange_options || {}
         | 
| 44 85 | 
             
                end
         | 
| 45 86 |  | 
| 46 87 | 
             
                def bind(options = {})
         | 
| 47 | 
            -
                  @binding_options  | 
| 88 | 
            +
                  @binding_options ||= {}
         | 
| 89 | 
            +
                  @binding_options.update(options)
         | 
| 48 90 | 
             
                end
         | 
| 49 91 |  | 
| 50 92 | 
             
                def binding_options
         | 
| @@ -60,17 +102,24 @@ module QueueingRabbit | |
| 60 102 | 
             
                end
         | 
| 61 103 |  | 
| 62 104 | 
             
                def listen(options = {})
         | 
| 63 | 
            -
                  @listening_options  | 
| 105 | 
            +
                  @listening_options ||= {}
         | 
| 106 | 
            +
                  @listening_options.update(options)
         | 
| 107 | 
            +
                end
         | 
| 108 | 
            +
                alias_method :subscribe, :listen
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                def publish(options = {})
         | 
| 111 | 
            +
                  @publishing_defaults ||= {}
         | 
| 112 | 
            +
                  @publishing_defaults.update(options)
         | 
| 64 113 | 
             
                end
         | 
| 65 114 |  | 
| 66 | 
            -
                def publishing_defaults | 
| 67 | 
            -
                  @publishing_defaults ||=  | 
| 115 | 
            +
                def publishing_defaults
         | 
| 116 | 
            +
                  @publishing_defaults ||= {}
         | 
| 117 | 
            +
                  {:routing_key => queue_name.to_s}.merge(@publishing_defaults)
         | 
| 68 118 | 
             
                end
         | 
| 69 119 |  | 
| 70 120 | 
             
                def enqueue(payload, options = {})
         | 
| 71 121 | 
             
                  QueueingRabbit.enqueue(self, payload, publishing_defaults.merge(options))
         | 
| 72 122 | 
             
                end
         | 
| 73 | 
            -
                alias_method :publish, :enqueue
         | 
| 74 123 |  | 
| 75 124 | 
             
              end
         | 
| 76 125 |  | 
| @@ -16,7 +16,7 @@ namespace :queueing_rabbit do | |
| 16 16 |  | 
| 17 17 | 
             
                begin
         | 
| 18 18 | 
             
                  worker = QueueingRabbit::Worker.new(*jobs)
         | 
| 19 | 
            -
                rescue QueueingRabbit:: | 
| 19 | 
            +
                rescue QueueingRabbit::JobNotPresentError, QueueingRabbit::JobNotFoundError
         | 
| 20 20 | 
             
                  abort "set JOB env var, e.g. $ JOB=ExportDataJob,CompressFileJob " \
         | 
| 21 21 | 
             
                        "rake queueing_rabbit:work"
         | 
| 22 22 | 
             
                end
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe 'Configuring jobs' do
         | 
| 4 | 
            +
              context 'when a job is inherited from a base class' do
         | 
| 5 | 
            +
                let(:base_class) {
         | 
| 6 | 
            +
                  Class.new(QueueingRabbit::AbstractJob) do
         | 
| 7 | 
            +
                    exchange 'exchange_name', :durable => true
         | 
| 8 | 
            +
                    channel :prefetch => 15
         | 
| 9 | 
            +
                    queue :durable => true
         | 
| 10 | 
            +
                    bind :ack => true
         | 
| 11 | 
            +
                    publish :persistent => true
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
                }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                let(:job_class) {
         | 
| 16 | 
            +
                  Class.new(base_class) do
         | 
| 17 | 
            +
                    queue 'queue_name'
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                subject { job_class }
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                its(:queue_name) { should == 'queue_name' }
         | 
| 24 | 
            +
                its(:exchange_name) { should == 'exchange_name' }
         | 
| 25 | 
            +
                its(:queue_options) { should include(:durable => true) }
         | 
| 26 | 
            +
                its(:binding_options) { should include(:ack => true) }
         | 
| 27 | 
            +
                its(:publishing_defaults) { should include(:persistent => true) }
         | 
| 28 | 
            +
                its(:channel_options) { should include(:prefetch => 15) }
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              context 'when cascading attributes', :ruby => '1.8.7' do
         | 
| 32 | 
            +
                let(:base_class) {
         | 
| 33 | 
            +
                  Class.new(QueueingRabbit::AbstractJob) do
         | 
| 34 | 
            +
                    exchange 'exchange_name', :durable => true
         | 
| 35 | 
            +
                    channel :prefetch => 15
         | 
| 36 | 
            +
                    queue :durable => true
         | 
| 37 | 
            +
                    bind :ack => true
         | 
| 38 | 
            +
                    publish :persistent => true
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
                }
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                let(:job_class) {
         | 
| 43 | 
            +
                  Class.new(base_class) do
         | 
| 44 | 
            +
                    channel :use_publisher_confirms => true
         | 
| 45 | 
            +
                    queue 'queue_name', :durable => false
         | 
| 46 | 
            +
                    bind :ack => false
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                }
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                subject { job_class }
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                its(:channel_options) { should include(:use_publisher_confirms => true,
         | 
| 53 | 
            +
                                                       :prefetch => 15) }
         | 
| 54 | 
            +
                its(:queue_options) { should include(:durable => false) }
         | 
| 55 | 
            +
                its(:binding_options) { should include(:ack => false) }
         | 
| 56 | 
            +
                its(:publishing_defaults) { should include(:persistent => true) }
         | 
| 57 | 
            +
             | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              context 'when using an extension' do
         | 
| 61 | 
            +
                let(:job_class) {
         | 
| 62 | 
            +
                  Class.new(QueueingRabbit::AbstractJob) do
         | 
| 63 | 
            +
                    include QueueingRabbit::JobExtensions::DirectExchange
         | 
| 64 | 
            +
                    queue 'queue_name'
         | 
| 65 | 
            +
                    exchange 'exchange_name'
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                subject { job_class }
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                its(:exchange_name) { should == 'exchange_name' }
         | 
| 72 | 
            +
                its(:exchange_options) { should include(:type => :direct) }
         | 
| 73 | 
            +
                its(:binding_options) { should include(:routing_key => 'queue_name')}
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
            end
         | 
| @@ -15,7 +15,7 @@ describe "Persistent asynchronous publishing and consuming" do | |
| 15 15 | 
             
                  Class.new(PrintLineJob) do
         | 
| 16 16 | 
             
                    queue 'persistent_print_line_job'
         | 
| 17 17 | 
             
                    listen :ack => true
         | 
| 18 | 
            -
                     | 
| 18 | 
            +
                    publish :persistent => true
         | 
| 19 19 | 
             
                    channel :use_publisher_confirms => true
         | 
| 20 20 |  | 
| 21 21 | 
             
                    def perform
         | 
| @@ -27,7 +27,6 @@ describe QueueingRabbit::AbstractJob do | |
| 27 27 | 
             
              it { should respond_to(:listen) }
         | 
| 28 28 | 
             
              it { should respond_to(:listen).with(1).argument }
         | 
| 29 29 | 
             
              it { should respond_to(:publishing_defaults) }
         | 
| 30 | 
            -
              it { should respond_to(:publishing_defaults).with(1).argument }
         | 
| 31 30 |  | 
| 32 31 | 
             
              its(:queue_name) { should == 'test_queue' }
         | 
| 33 32 | 
             
              its(:queue_options) { should include(:durable => true) }
         | 
| @@ -27,7 +27,6 @@ describe QueueingRabbit::AbstractJob do | |
| 27 27 | 
             
              it { should respond_to(:listen) }
         | 
| 28 28 | 
             
              it { should respond_to(:listen).with(1).argument }
         | 
| 29 29 | 
             
              it { should respond_to(:publishing_defaults) }
         | 
| 30 | 
            -
              it { should respond_to(:publishing_defaults).with(1).argument }
         | 
| 31 30 |  | 
| 32 31 | 
             
              its(:queue_name) { should == 'test_queue' }
         | 
| 33 32 | 
             
              its(:queue_options) { should include(:durable => true) }
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: queueing_rabbit
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 12 | 
            +
            date: 2013-09-02 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: amqp
         | 
| @@ -121,6 +121,7 @@ files: | |
| 121 121 | 
             
            - queueing_rabbit.gemspec
         | 
| 122 122 | 
             
            - spec/integration/asynchronous_publishing_and_consuming_spec.rb
         | 
| 123 123 | 
             
            - spec/integration/asynchronous_publishing_and_consuming_with_retries_spec.rb
         | 
| 124 | 
            +
            - spec/integration/configuration_spec.rb
         | 
| 124 125 | 
             
            - spec/integration/direct_exchange_asynchronous_publishing_and_consuming_spec.rb
         | 
| 125 126 | 
             
            - spec/integration/jobs/print_line_job.rb
         | 
| 126 127 | 
             
            - spec/integration/json_job_asynchronous_publishing_and_consuming_spec.rb
         | 
| @@ -159,7 +160,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 159 160 | 
             
                  version: '0'
         | 
| 160 161 | 
             
                  segments:
         | 
| 161 162 | 
             
                  - 0
         | 
| 162 | 
            -
                  hash:  | 
| 163 | 
            +
                  hash: -615049155772679483
         | 
| 163 164 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 164 165 | 
             
              none: false
         | 
| 165 166 | 
             
              requirements:
         | 
| @@ -168,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 168 169 | 
             
                  version: '0'
         | 
| 169 170 | 
             
                  segments:
         | 
| 170 171 | 
             
                  - 0
         | 
| 171 | 
            -
                  hash:  | 
| 172 | 
            +
                  hash: -615049155772679483
         | 
| 172 173 | 
             
            requirements: []
         | 
| 173 174 | 
             
            rubyforge_project: 
         | 
| 174 175 | 
             
            rubygems_version: 1.8.25
         | 
| @@ -178,6 +179,7 @@ summary: QueueingRabbit is an AMQP-based queueing system | |
| 178 179 | 
             
            test_files:
         | 
| 179 180 | 
             
            - spec/integration/asynchronous_publishing_and_consuming_spec.rb
         | 
| 180 181 | 
             
            - spec/integration/asynchronous_publishing_and_consuming_with_retries_spec.rb
         | 
| 182 | 
            +
            - spec/integration/configuration_spec.rb
         | 
| 181 183 | 
             
            - spec/integration/direct_exchange_asynchronous_publishing_and_consuming_spec.rb
         | 
| 182 184 | 
             
            - spec/integration/jobs/print_line_job.rb
         | 
| 183 185 | 
             
            - spec/integration/json_job_asynchronous_publishing_and_consuming_spec.rb
         |