que 0.9.2 → 0.10.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/docs/error_handling.md +20 -2
- data/lib/que.rb +26 -0
- data/lib/que/migrations.rb +1 -23
- data/lib/que/rake_tasks.rb +7 -2
- data/lib/que/version.rb +1 -1
- data/spec/unit/migrations_spec.rb +0 -33
- data/spec/unit/transaction_spec.rb +34 -0
- metadata +12 -10
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ea48a3d241852be82ac3310d9a9b77dd5c752c66
         | 
| 4 | 
            +
              data.tar.gz: 9c959569e9b5eb520dffde4a21f08875d9efbbce
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 794d3b3a6e55beaa75a8142324a8eac2512505114b401aa1b306ef20e0e08f58913a8bb6685dd599a4bcadbdfec295c97637b22b6ddfdf8d2862225444e76ced
         | 
| 7 | 
            +
              data.tar.gz: b186100af249195025f731e551155dcdcd9e4797a7164d0c71a9604842e5a3d604bd47f6b5331e0773bdfad1018332d21463266675251afeb5034407fc7dcae6
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,3 +1,11 @@ | |
| 1 | 
            +
            ### 0.10.0 (2015-03-18)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            *   When working jobs via the rake task, Rails applications are now eager-loaded if present, to avoid problems with multithreading and autoloading. (#96) (hmarr)
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            *   The que:work rake task now uses whatever logger Que is configured to use normally, rather than forcing the use of STDOUT. (#95)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            *   Add Que.transaction() helper method, to aid in transaction management in migrations or when the user's ORM doesn't provide one. (#81)
         | 
| 8 | 
            +
             | 
| 1 9 | 
             
            ### 0.9.2 (2015-02-05)
         | 
| 2 10 |  | 
| 3 11 | 
             
            *   Fix a bug wherein the at_exit hook in the railtie wasn't waiting for jobs to finish before exiting.
         | 
    
        data/docs/error_handling.md
    CHANGED
    
    | @@ -20,6 +20,24 @@ Unlike DelayedJob, however, there is currently no maximum number of failures aft | |
| 20 20 |  | 
| 21 21 | 
             
            If you're using an error notification system (highly recommended, of course), you can hook Que into it by setting a callable as the error handler:
         | 
| 22 22 |  | 
| 23 | 
            -
                Que.error_handler = proc do |error|
         | 
| 24 | 
            -
                  # Do whatever you want with the error object.
         | 
| 23 | 
            +
                Que.error_handler = proc do |error, job|
         | 
| 24 | 
            +
                  # Do whatever you want with the error object or job row here.
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  # Note that the job passed is not the actual job object, but the hash
         | 
| 27 | 
            +
                  # representing the job row in the database, which looks like:
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  # {
         | 
| 30 | 
            +
                  #   "queue" => "my_queue",
         | 
| 31 | 
            +
                  #   "priority" => 100,
         | 
| 32 | 
            +
                  #   "run_at" => 2015-03-06 11:07:08 -0500,
         | 
| 33 | 
            +
                  #   "job_id" => 65,
         | 
| 34 | 
            +
                  #   "job_class" => "MyJob",
         | 
| 35 | 
            +
                  #   "args" => ['argument', 78],
         | 
| 36 | 
            +
                  #   "error_count" => 0
         | 
| 37 | 
            +
                  # }
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  # This is done because the job may not have been able to be deserialized
         | 
| 40 | 
            +
                  # properly, if the name of the job class was changed or the job is being
         | 
| 41 | 
            +
                  # retrieved and worked by the wrong app. The job argument may also be
         | 
| 42 | 
            +
                  # nil, if there was a connection failure or something similar.
         | 
| 25 43 | 
             
                end
         | 
    
        data/lib/que.rb
    CHANGED
    
    | @@ -96,6 +96,32 @@ module Que | |
| 96 96 | 
             
                  @log_formatter ||= JSON_MODULE.method(:dump)
         | 
| 97 97 | 
             
                end
         | 
| 98 98 |  | 
| 99 | 
            +
                # A helper method to manage transactions, used mainly by the migration
         | 
| 100 | 
            +
                # system. It's available for general use, but if you're using an ORM that
         | 
| 101 | 
            +
                # provides its own transaction helper, be sure to use that instead, or the
         | 
| 102 | 
            +
                # two may interfere with one another.
         | 
| 103 | 
            +
                def transaction
         | 
| 104 | 
            +
                  adapter.checkout do
         | 
| 105 | 
            +
                    if adapter.in_transaction?
         | 
| 106 | 
            +
                      yield
         | 
| 107 | 
            +
                    else
         | 
| 108 | 
            +
                      begin
         | 
| 109 | 
            +
                        execute "BEGIN"
         | 
| 110 | 
            +
                        yield
         | 
| 111 | 
            +
                      rescue => error
         | 
| 112 | 
            +
                        raise
         | 
| 113 | 
            +
                      ensure
         | 
| 114 | 
            +
                        # Handle a raised error or a killed thread.
         | 
| 115 | 
            +
                        if error || Thread.current.status == 'aborting'
         | 
| 116 | 
            +
                          execute "ROLLBACK"
         | 
| 117 | 
            +
                        else
         | 
| 118 | 
            +
                          execute "COMMIT"
         | 
| 119 | 
            +
                        end
         | 
| 120 | 
            +
                      end
         | 
| 121 | 
            +
                    end
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 99 125 | 
             
                # Copy some of the Worker class' config methods here for convenience.
         | 
| 100 126 | 
             
                [:mode, :mode=, :worker_count, :worker_count=, :wake_interval, :wake_interval=, :wake!, :wake_all!].each do |meth|
         | 
| 101 127 | 
             
                  define_method(meth) { |*args| Worker.send(meth, *args) }
         | 
    
        data/lib/que/migrations.rb
    CHANGED
    
    | @@ -7,7 +7,7 @@ module Que | |
| 7 7 |  | 
| 8 8 | 
             
                class << self
         | 
| 9 9 | 
             
                  def migrate!(options = {:version => CURRENT_VERSION})
         | 
| 10 | 
            -
                    transaction do
         | 
| 10 | 
            +
                    Que.transaction do
         | 
| 11 11 | 
             
                      version = options[:version]
         | 
| 12 12 |  | 
| 13 13 | 
             
                      if (current = db_version) == version
         | 
| @@ -52,28 +52,6 @@ module Que | |
| 52 52 | 
             
                    i = version.to_i
         | 
| 53 53 | 
             
                    Que.execute "COMMENT ON TABLE que_jobs IS '#{i}'" unless i.zero?
         | 
| 54 54 | 
             
                  end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                  def transaction
         | 
| 57 | 
            -
                    Que.adapter.checkout do
         | 
| 58 | 
            -
                      if Que.adapter.in_transaction?
         | 
| 59 | 
            -
                        yield
         | 
| 60 | 
            -
                      else
         | 
| 61 | 
            -
                        begin
         | 
| 62 | 
            -
                          Que.execute "BEGIN"
         | 
| 63 | 
            -
                          yield
         | 
| 64 | 
            -
                        rescue => error
         | 
| 65 | 
            -
                          raise
         | 
| 66 | 
            -
                        ensure
         | 
| 67 | 
            -
                          # Handle a raised error or a killed thread.
         | 
| 68 | 
            -
                          if error || Thread.current.status == 'aborting'
         | 
| 69 | 
            -
                            Que.execute "ROLLBACK"
         | 
| 70 | 
            -
                          else
         | 
| 71 | 
            -
                            Que.execute "COMMIT"
         | 
| 72 | 
            -
                          end
         | 
| 73 | 
            -
                        end
         | 
| 74 | 
            -
                      end
         | 
| 75 | 
            -
                    end
         | 
| 76 | 
            -
                  end
         | 
| 77 55 | 
             
                end
         | 
| 78 56 | 
             
              end
         | 
| 79 57 | 
             
            end
         | 
    
        data/lib/que/rake_tasks.rb
    CHANGED
    
    | @@ -1,9 +1,14 @@ | |
| 1 1 | 
             
            namespace :que do
         | 
| 2 2 | 
             
              desc "Process Que's jobs using a worker pool"
         | 
| 3 3 | 
             
              task :work => :environment do
         | 
| 4 | 
            -
                 | 
| 4 | 
            +
                if defined?(::Rails) && Rails.respond_to?(:application)
         | 
| 5 | 
            +
                  # ActiveSupport's dependency autoloading isn't threadsafe, and Que uses
         | 
| 6 | 
            +
                  # multiple threads, which means that eager loading is necessary. Rails
         | 
| 7 | 
            +
                  # explicitly prevents eager loading when the environment task is invoked,
         | 
| 8 | 
            +
                  # so we need to manually eager load the app here.
         | 
| 9 | 
            +
                  Rails.application.eager_load!
         | 
| 10 | 
            +
                end
         | 
| 5 11 |  | 
| 6 | 
            -
                Que.logger        = Logger.new(STDOUT)
         | 
| 7 12 | 
             
                Que.logger.level  = Logger.const_get((ENV['QUE_LOG_LEVEL'] || 'INFO').upcase)
         | 
| 8 13 | 
             
                Que.worker_count  = (ENV['QUE_WORKER_COUNT'] || 4).to_i
         | 
| 9 14 | 
             
                Que.wake_interval = (ENV['QUE_WAKE_INTERVAL'] || 0.1).to_f
         | 
    
        data/lib/que/version.rb
    CHANGED
    
    
| @@ -79,37 +79,4 @@ describe Que::Migrations do | |
| 79 79 | 
             
                Que::Migrations.migrate!
         | 
| 80 80 | 
             
                DB.table_exists?(:que_jobs).should be true
         | 
| 81 81 | 
             
              end
         | 
| 82 | 
            -
             | 
| 83 | 
            -
              it "should use transactions to protect its migrations from errors" do
         | 
| 84 | 
            -
                proc do
         | 
| 85 | 
            -
                  Que::Migrations.transaction do
         | 
| 86 | 
            -
                    Que.execute "DROP TABLE que_jobs"
         | 
| 87 | 
            -
                    Que.execute "invalid SQL syntax"
         | 
| 88 | 
            -
                  end
         | 
| 89 | 
            -
                end.should raise_error(PG::Error)
         | 
| 90 | 
            -
             | 
| 91 | 
            -
                DB.table_exists?(:que_jobs).should be true
         | 
| 92 | 
            -
              end
         | 
| 93 | 
            -
             | 
| 94 | 
            -
              # In Ruby 1.9, it's impossible to tell inside an ensure block whether the
         | 
| 95 | 
            -
              # currently executing thread has been killed.
         | 
| 96 | 
            -
              unless RUBY_VERSION.start_with?('1.9')
         | 
| 97 | 
            -
                it "should use transactions to protect its migrations from killed threads" do
         | 
| 98 | 
            -
                  q = Queue.new
         | 
| 99 | 
            -
             | 
| 100 | 
            -
                  t = Thread.new do
         | 
| 101 | 
            -
                    Que::Migrations.transaction do
         | 
| 102 | 
            -
                      Que.execute "DROP TABLE que_jobs"
         | 
| 103 | 
            -
                      q.push :go!
         | 
| 104 | 
            -
                      sleep
         | 
| 105 | 
            -
                    end
         | 
| 106 | 
            -
                  end
         | 
| 107 | 
            -
             | 
| 108 | 
            -
                  q.pop
         | 
| 109 | 
            -
                  t.kill
         | 
| 110 | 
            -
                  t.join
         | 
| 111 | 
            -
             | 
| 112 | 
            -
                  DB.table_exists?(:que_jobs).should be true
         | 
| 113 | 
            -
                end
         | 
| 114 | 
            -
              end
         | 
| 115 82 | 
             
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Que, '.transaction' do
         | 
| 4 | 
            +
              it "should use a transaction to rollback changes in the event of an error" do
         | 
| 5 | 
            +
                proc do
         | 
| 6 | 
            +
                  Que.transaction do
         | 
| 7 | 
            +
                    Que.execute "DROP TABLE que_jobs"
         | 
| 8 | 
            +
                    Que.execute "invalid SQL syntax"
         | 
| 9 | 
            +
                  end
         | 
| 10 | 
            +
                end.should raise_error(PG::Error)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                DB.table_exists?(:que_jobs).should be true
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              unless RUBY_VERSION.start_with?('1.9')
         | 
| 16 | 
            +
                it "should rollback correctly in the event of a killed thread" do
         | 
| 17 | 
            +
                  q = Queue.new
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  t = Thread.new do
         | 
| 20 | 
            +
                    Que.transaction do
         | 
| 21 | 
            +
                      Que.execute "DROP TABLE que_jobs"
         | 
| 22 | 
            +
                      q.push :go!
         | 
| 23 | 
            +
                      sleep
         | 
| 24 | 
            +
                    end
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  q.pop
         | 
| 28 | 
            +
                  t.kill
         | 
| 29 | 
            +
                  t.join
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  DB.table_exists?(:que_jobs).should be true
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,27 +1,27 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: que
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.10.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Chris Hanks
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-03-18 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - ~>
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 19 | 
             
                    version: '1.3'
         | 
| 20 20 | 
             
              type: :development
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - ~>
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 26 | 
             
                    version: '1.3'
         | 
| 27 27 | 
             
            description: A job queue that uses PostgreSQL's advisory locks for speed and reliability.
         | 
| @@ -31,9 +31,9 @@ executables: [] | |
| 31 31 | 
             
            extensions: []
         | 
| 32 32 | 
             
            extra_rdoc_files: []
         | 
| 33 33 | 
             
            files:
         | 
| 34 | 
            -
            - .gitignore
         | 
| 35 | 
            -
            - .rspec
         | 
| 36 | 
            -
            - .travis.yml
         | 
| 34 | 
            +
            - ".gitignore"
         | 
| 35 | 
            +
            - ".rspec"
         | 
| 36 | 
            +
            - ".travis.yml"
         | 
| 37 37 | 
             
            - CHANGELOG.md
         | 
| 38 38 | 
             
            - Gemfile
         | 
| 39 39 | 
             
            - LICENSE.txt
         | 
| @@ -97,6 +97,7 @@ files: | |
| 97 97 | 
             
            - spec/unit/run_spec.rb
         | 
| 98 98 | 
             
            - spec/unit/states_spec.rb
         | 
| 99 99 | 
             
            - spec/unit/stats_spec.rb
         | 
| 100 | 
            +
            - spec/unit/transaction_spec.rb
         | 
| 100 101 | 
             
            - spec/unit/work_spec.rb
         | 
| 101 102 | 
             
            - spec/unit/worker_spec.rb
         | 
| 102 103 | 
             
            - tasks/benchmark.rb
         | 
| @@ -112,17 +113,17 @@ require_paths: | |
| 112 113 | 
             
            - lib
         | 
| 113 114 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 114 115 | 
             
              requirements:
         | 
| 115 | 
            -
              - -  | 
| 116 | 
            +
              - - ">="
         | 
| 116 117 | 
             
                - !ruby/object:Gem::Version
         | 
| 117 118 | 
             
                  version: '0'
         | 
| 118 119 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 119 120 | 
             
              requirements:
         | 
| 120 | 
            -
              - -  | 
| 121 | 
            +
              - - ">="
         | 
| 121 122 | 
             
                - !ruby/object:Gem::Version
         | 
| 122 123 | 
             
                  version: '0'
         | 
| 123 124 | 
             
            requirements: []
         | 
| 124 125 | 
             
            rubyforge_project: 
         | 
| 125 | 
            -
            rubygems_version: 2. | 
| 126 | 
            +
            rubygems_version: 2.4.6
         | 
| 126 127 | 
             
            signing_key: 
         | 
| 127 128 | 
             
            specification_version: 4
         | 
| 128 129 | 
             
            summary: A PostgreSQL-based Job Queue
         | 
| @@ -150,5 +151,6 @@ test_files: | |
| 150 151 | 
             
            - spec/unit/run_spec.rb
         | 
| 151 152 | 
             
            - spec/unit/states_spec.rb
         | 
| 152 153 | 
             
            - spec/unit/stats_spec.rb
         | 
| 154 | 
            +
            - spec/unit/transaction_spec.rb
         | 
| 153 155 | 
             
            - spec/unit/work_spec.rb
         | 
| 154 156 | 
             
            - spec/unit/worker_spec.rb
         |