steini-resque 1.18.5
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/HISTORY.md +322 -0
 - data/LICENSE +20 -0
 - data/README.markdown +881 -0
 - data/Rakefile +78 -0
 - data/bin/resque +81 -0
 - data/bin/resque-web +23 -0
 - data/lib/resque.rb +352 -0
 - data/lib/resque/errors.rb +10 -0
 - data/lib/resque/failure.rb +70 -0
 - data/lib/resque/failure/base.rb +64 -0
 - data/lib/resque/failure/hoptoad.rb +48 -0
 - data/lib/resque/failure/multiple.rb +54 -0
 - data/lib/resque/failure/redis.rb +51 -0
 - data/lib/resque/helpers.rb +63 -0
 - data/lib/resque/job.rb +205 -0
 - data/lib/resque/plugin.rb +56 -0
 - data/lib/resque/server.rb +231 -0
 - data/lib/resque/server/public/favicon.ico +0 -0
 - data/lib/resque/server/public/idle.png +0 -0
 - data/lib/resque/server/public/jquery-1.3.2.min.js +19 -0
 - data/lib/resque/server/public/jquery.relatize_date.js +95 -0
 - data/lib/resque/server/public/poll.png +0 -0
 - data/lib/resque/server/public/ranger.js +73 -0
 - data/lib/resque/server/public/reset.css +48 -0
 - data/lib/resque/server/public/style.css +85 -0
 - data/lib/resque/server/public/working.png +0 -0
 - data/lib/resque/server/test_helper.rb +19 -0
 - data/lib/resque/server/views/error.erb +1 -0
 - data/lib/resque/server/views/failed.erb +64 -0
 - data/lib/resque/server/views/key_sets.erb +19 -0
 - data/lib/resque/server/views/key_string.erb +11 -0
 - data/lib/resque/server/views/layout.erb +44 -0
 - data/lib/resque/server/views/next_more.erb +10 -0
 - data/lib/resque/server/views/overview.erb +4 -0
 - data/lib/resque/server/views/queues.erb +49 -0
 - data/lib/resque/server/views/stats.erb +62 -0
 - data/lib/resque/server/views/workers.erb +109 -0
 - data/lib/resque/server/views/working.erb +72 -0
 - data/lib/resque/stat.rb +53 -0
 - data/lib/resque/tasks.rb +51 -0
 - data/lib/resque/version.rb +3 -0
 - data/lib/resque/worker.rb +533 -0
 - data/lib/tasks/redis.rake +161 -0
 - data/lib/tasks/resque.rake +2 -0
 - data/test/hoptoad_test.rb +25 -0
 - data/test/job_hooks_test.rb +363 -0
 - data/test/job_plugins_test.rb +230 -0
 - data/test/plugin_test.rb +116 -0
 - data/test/redis-test.conf +115 -0
 - data/test/resque-web_test.rb +53 -0
 - data/test/resque_test.rb +259 -0
 - data/test/test_helper.rb +148 -0
 - data/test/worker_test.rb +332 -0
 - metadata +183 -0
 
| 
         @@ -0,0 +1,161 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Inspired by rabbitmq.rake the Redbox project at http://github.com/rick/redbox/tree/master
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'fileutils'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'open-uri'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'pathname'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class RedisRunner
         
     | 
| 
      
 7 
     | 
    
         
            +
              def self.redis_dir
         
     | 
| 
      
 8 
     | 
    
         
            +
                @redis_dir ||= if ENV['PREFIX']
         
     | 
| 
      
 9 
     | 
    
         
            +
                                 Pathname.new(ENV['PREFIX'])
         
     | 
| 
      
 10 
     | 
    
         
            +
                               else
         
     | 
| 
      
 11 
     | 
    
         
            +
                                 Pathname.new(`which redis-server`) + '..' + '..'
         
     | 
| 
      
 12 
     | 
    
         
            +
                               end
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def self.bin_dir
         
     | 
| 
      
 16 
     | 
    
         
            +
                redis_dir + 'bin'
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def self.config
         
     | 
| 
      
 20 
     | 
    
         
            +
                @config ||= if File.exists?(redis_dir + 'etc/redis.conf')
         
     | 
| 
      
 21 
     | 
    
         
            +
                              redis_dir + 'etc/redis.conf'
         
     | 
| 
      
 22 
     | 
    
         
            +
                            else
         
     | 
| 
      
 23 
     | 
    
         
            +
                              redis_dir + '../etc/redis.conf'
         
     | 
| 
      
 24 
     | 
    
         
            +
                            end
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              def self.dtach_socket
         
     | 
| 
      
 28 
     | 
    
         
            +
                '/tmp/redis.dtach'
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              # Just check for existance of dtach socket
         
     | 
| 
      
 32 
     | 
    
         
            +
              def self.running?
         
     | 
| 
      
 33 
     | 
    
         
            +
                File.exists? dtach_socket
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
              def self.start
         
     | 
| 
      
 37 
     | 
    
         
            +
                puts 'Detach with Ctrl+\  Re-attach with rake redis:attach'
         
     | 
| 
      
 38 
     | 
    
         
            +
                sleep 1
         
     | 
| 
      
 39 
     | 
    
         
            +
                command = "#{bin_dir}/dtach -A #{dtach_socket} #{bin_dir}/redis-server #{config}"
         
     | 
| 
      
 40 
     | 
    
         
            +
                sh command
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              def self.attach
         
     | 
| 
      
 44 
     | 
    
         
            +
                exec "#{bin_dir}/dtach -a #{dtach_socket}"
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def self.stop
         
     | 
| 
      
 48 
     | 
    
         
            +
                sh 'echo "SHUTDOWN" | nc localhost 6379'
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
            INSTALL_DIR = ENV['INSTALL_DIR'] || '/tmp/redis'
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
            namespace :redis do
         
     | 
| 
      
 55 
     | 
    
         
            +
              desc 'About redis'
         
     | 
| 
      
 56 
     | 
    
         
            +
              task :about do
         
     | 
| 
      
 57 
     | 
    
         
            +
                puts "\nSee http://code.google.com/p/redis/ for information about redis.\n\n"
         
     | 
| 
      
 58 
     | 
    
         
            +
              end
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              desc 'Start redis'
         
     | 
| 
      
 61 
     | 
    
         
            +
              task :start do
         
     | 
| 
      
 62 
     | 
    
         
            +
                RedisRunner.start
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
              desc 'Stop redis'
         
     | 
| 
      
 66 
     | 
    
         
            +
              task :stop do
         
     | 
| 
      
 67 
     | 
    
         
            +
                RedisRunner.stop
         
     | 
| 
      
 68 
     | 
    
         
            +
              end
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
              desc 'Restart redis'
         
     | 
| 
      
 71 
     | 
    
         
            +
              task :restart do
         
     | 
| 
      
 72 
     | 
    
         
            +
                RedisRunner.stop
         
     | 
| 
      
 73 
     | 
    
         
            +
                RedisRunner.start
         
     | 
| 
      
 74 
     | 
    
         
            +
              end
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
              desc 'Attach to redis dtach socket'
         
     | 
| 
      
 77 
     | 
    
         
            +
              task :attach do
         
     | 
| 
      
 78 
     | 
    
         
            +
                RedisRunner.attach
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
              desc <<-DOC
         
     | 
| 
      
 82 
     | 
    
         
            +
              Install the latest verison of Redis from Github (requires git, duh).
         
     | 
| 
      
 83 
     | 
    
         
            +
                Use INSTALL_DIR env var like "rake redis:install INSTALL_DIR=~/tmp"
         
     | 
| 
      
 84 
     | 
    
         
            +
                in order to get an alternate location for your install files.
         
     | 
| 
      
 85 
     | 
    
         
            +
              DOC
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
              task :install => [:about, :download, :make] do
         
     | 
| 
      
 88 
     | 
    
         
            +
                bin_dir = '/usr/bin'
         
     | 
| 
      
 89 
     | 
    
         
            +
                conf_dir = '/etc'
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                if ENV['PREFIX']
         
     | 
| 
      
 92 
     | 
    
         
            +
                  bin_dir = "#{ENV['PREFIX']}/bin"
         
     | 
| 
      
 93 
     | 
    
         
            +
                  sh "mkdir -p #{bin_dir}" unless File.exists?("#{bin_dir}")
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                  conf_dir = "#{ENV['PREFIX']}/etc"
         
     | 
| 
      
 96 
     | 
    
         
            +
                  sh "mkdir -p #{conf_dir}" unless File.exists?("#{conf_dir}")
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                %w(redis-benchmark redis-cli redis-server).each do |bin|
         
     | 
| 
      
 100 
     | 
    
         
            +
                  sh "cp #{INSTALL_DIR}/src/#{bin} #{bin_dir}"
         
     | 
| 
      
 101 
     | 
    
         
            +
                end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                puts "Installed redis-benchmark, redis-cli and redis-server to #{bin_dir}"
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
                unless File.exists?("#{conf_dir}/redis.conf")
         
     | 
| 
      
 106 
     | 
    
         
            +
                  sh "cp #{INSTALL_DIR}/redis.conf #{conf_dir}/redis.conf"
         
     | 
| 
      
 107 
     | 
    
         
            +
                  puts "Installed redis.conf to #{conf_dir} \n You should look at this file!"
         
     | 
| 
      
 108 
     | 
    
         
            +
                end
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              task :make do
         
     | 
| 
      
 112 
     | 
    
         
            +
                sh "cd #{INSTALL_DIR}/src && make clean"
         
     | 
| 
      
 113 
     | 
    
         
            +
                sh "cd #{INSTALL_DIR}/src && make"
         
     | 
| 
      
 114 
     | 
    
         
            +
              end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
              desc "Download package"
         
     | 
| 
      
 117 
     | 
    
         
            +
              task :download do
         
     | 
| 
      
 118 
     | 
    
         
            +
                sh "rm -rf #{INSTALL_DIR}/" if File.exists?("#{INSTALL_DIR}/.svn")
         
     | 
| 
      
 119 
     | 
    
         
            +
                sh "git clone git://github.com/antirez/redis.git #{INSTALL_DIR}" unless File.exists?(INSTALL_DIR)
         
     | 
| 
      
 120 
     | 
    
         
            +
                sh "cd #{INSTALL_DIR} && git pull" if File.exists?("#{INSTALL_DIR}/.git")
         
     | 
| 
      
 121 
     | 
    
         
            +
              end
         
     | 
| 
      
 122 
     | 
    
         
            +
            end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
            namespace :dtach do
         
     | 
| 
      
 125 
     | 
    
         
            +
              desc 'About dtach'
         
     | 
| 
      
 126 
     | 
    
         
            +
              task :about do
         
     | 
| 
      
 127 
     | 
    
         
            +
                puts "\nSee http://dtach.sourceforge.net/ for information about dtach.\n\n"
         
     | 
| 
      
 128 
     | 
    
         
            +
              end
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
              desc 'Install dtach 0.8 from source'
         
     | 
| 
      
 131 
     | 
    
         
            +
              task :install => [:about, :download, :make] do
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                bin_dir = "/usr/bin"
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                if ENV['PREFIX']
         
     | 
| 
      
 137 
     | 
    
         
            +
                  bin_dir = "#{ENV['PREFIX']}/bin"
         
     | 
| 
      
 138 
     | 
    
         
            +
                  sh "mkdir -p #{bin_dir}" unless File.exists?("#{bin_dir}")
         
     | 
| 
      
 139 
     | 
    
         
            +
                end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                sh "cp #{INSTALL_DIR}/dtach-0.8/dtach #{bin_dir}"
         
     | 
| 
      
 142 
     | 
    
         
            +
              end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
              task :make do
         
     | 
| 
      
 145 
     | 
    
         
            +
                sh "cd #{INSTALL_DIR}/dtach-0.8/ && ./configure && make"
         
     | 
| 
      
 146 
     | 
    
         
            +
              end
         
     | 
| 
      
 147 
     | 
    
         
            +
             
     | 
| 
      
 148 
     | 
    
         
            +
              desc "Download package"
         
     | 
| 
      
 149 
     | 
    
         
            +
              task :download do
         
     | 
| 
      
 150 
     | 
    
         
            +
                unless File.exists?("#{INSTALL_DIR}/dtach-0.8.tar.gz")
         
     | 
| 
      
 151 
     | 
    
         
            +
                  require 'net/http'
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
                  url = 'http://downloads.sourceforge.net/project/dtach/dtach/0.8/dtach-0.8.tar.gz'
         
     | 
| 
      
 154 
     | 
    
         
            +
                  open("#{INSTALL_DIR}/dtach-0.8.tar.gz", 'wb') do |file| file.write(open(url).read) end
         
     | 
| 
      
 155 
     | 
    
         
            +
                end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                unless File.directory?("#{INSTALL_DIR}/dtach-0.8")
         
     | 
| 
      
 158 
     | 
    
         
            +
                  sh "cd #{INSTALL_DIR} && tar xzf dtach-0.8.tar.gz"
         
     | 
| 
      
 159 
     | 
    
         
            +
                end
         
     | 
| 
      
 160 
     | 
    
         
            +
              end
         
     | 
| 
      
 161 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              require 'hoptoad_notifier'
         
     | 
| 
      
 5 
     | 
    
         
            +
            rescue LoadError
         
     | 
| 
      
 6 
     | 
    
         
            +
              warn "Install hoptoad_notifier gem to run Hoptoad tests."
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            if defined? HoptoadNotifier
         
     | 
| 
      
 10 
     | 
    
         
            +
              context "Hoptoad" do
         
     | 
| 
      
 11 
     | 
    
         
            +
                test "should be notified of an error" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  exception = StandardError.new("BOOM")
         
     | 
| 
      
 13 
     | 
    
         
            +
                  worker = Resque::Worker.new(:test)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  queue = "test"
         
     | 
| 
      
 15 
     | 
    
         
            +
                  payload = {'class' => Object, 'args' => 66}
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  HoptoadNotifier.expects(:notify_or_ignore).with(
         
     | 
| 
      
 18 
     | 
    
         
            +
                    exception,
         
     | 
| 
      
 19 
     | 
    
         
            +
                    :parameters => {:payload_class => 'Object', :payload_args => '66'})
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  backend = Resque::Failure::Hoptoad.new(exception, worker, queue, payload)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  backend.save
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,363 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            context "Resque::Job before_perform" do
         
     | 
| 
      
 4 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              class ::BeforePerformJob
         
     | 
| 
      
 7 
     | 
    
         
            +
                def self.before_perform_record_history(history)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  history << :before_perform
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              test "it runs before_perform before perform" do
         
     | 
| 
      
 17 
     | 
    
         
            +
                result = perform_job(BeforePerformJob, history=[])
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal true, result, "perform returned true"
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert_equal history, [:before_perform, :perform]
         
     | 
| 
      
 20 
     | 
    
         
            +
              end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              class ::BeforePerformJobFails
         
     | 
| 
      
 23 
     | 
    
         
            +
                def self.before_perform_fail_job(history)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  history << :before_perform
         
     | 
| 
      
 25 
     | 
    
         
            +
                  raise StandardError
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              test "raises an error and does not perform if before_perform fails" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  perform_job(BeforePerformJobFails, history)
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
                assert_equal history, [:before_perform], "Only before_perform was run"
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              class ::BeforePerformJobAborts
         
     | 
| 
      
 41 
     | 
    
         
            +
                def self.before_perform_abort(history)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  history << :before_perform
         
     | 
| 
      
 43 
     | 
    
         
            +
                  raise Resque::Job::DontPerform
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              test "does not perform if before_perform raises Resque::Job::DontPerform" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                result = perform_job(BeforePerformJobAborts, history=[])
         
     | 
| 
      
 52 
     | 
    
         
            +
                assert_equal false, result, "perform returned false"
         
     | 
| 
      
 53 
     | 
    
         
            +
                assert_equal history, [:before_perform], "Only before_perform was run"
         
     | 
| 
      
 54 
     | 
    
         
            +
              end
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
            context "Resque::Job after_perform" do
         
     | 
| 
      
 58 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
              class ::AfterPerformJob
         
     | 
| 
      
 61 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
                def self.after_perform_record_history(history)
         
     | 
| 
      
 65 
     | 
    
         
            +
                  history << :after_perform
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
              end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
              test "it runs after_perform after perform" do
         
     | 
| 
      
 70 
     | 
    
         
            +
                result = perform_job(AfterPerformJob, history=[])
         
     | 
| 
      
 71 
     | 
    
         
            +
                assert_equal true, result, "perform returned true"
         
     | 
| 
      
 72 
     | 
    
         
            +
                assert_equal history, [:perform, :after_perform]
         
     | 
| 
      
 73 
     | 
    
         
            +
              end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
              class ::AfterPerformJobFails
         
     | 
| 
      
 76 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 77 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
                def self.after_perform_fail_job(history)
         
     | 
| 
      
 80 
     | 
    
         
            +
                  history << :after_perform
         
     | 
| 
      
 81 
     | 
    
         
            +
                  raise StandardError
         
     | 
| 
      
 82 
     | 
    
         
            +
                end
         
     | 
| 
      
 83 
     | 
    
         
            +
              end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
              test "raises an error but has already performed if after_perform fails" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 87 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 88 
     | 
    
         
            +
                  perform_job(AfterPerformJobFails, history)
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
                assert_equal history, [:perform, :after_perform], "Only after_perform was run"
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
            end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            context "Resque::Job around_perform" do
         
     | 
| 
      
 95 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              class ::AroundPerformJob
         
     | 
| 
      
 98 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
                def self.around_perform_record_history(history)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 103 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 104 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 105 
     | 
    
         
            +
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
              end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
              test "it runs around_perform then yields in order to perform" do
         
     | 
| 
      
 109 
     | 
    
         
            +
                result = perform_job(AroundPerformJob, history=[])
         
     | 
| 
      
 110 
     | 
    
         
            +
                assert_equal true, result, "perform returned true"
         
     | 
| 
      
 111 
     | 
    
         
            +
                assert_equal history, [:start_around_perform, :perform, :finish_around_perform]
         
     | 
| 
      
 112 
     | 
    
         
            +
              end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
              class ::AroundPerformJobFailsBeforePerforming
         
     | 
| 
      
 115 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 116 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
                def self.around_perform_fail(history)
         
     | 
| 
      
 119 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 120 
     | 
    
         
            +
                  raise StandardError
         
     | 
| 
      
 121 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 122 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
      
 124 
     | 
    
         
            +
              end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
              test "raises an error and does not perform if around_perform fails before yielding" do
         
     | 
| 
      
 127 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 128 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 129 
     | 
    
         
            +
                  perform_job(AroundPerformJobFailsBeforePerforming, history)
         
     | 
| 
      
 130 
     | 
    
         
            +
                end
         
     | 
| 
      
 131 
     | 
    
         
            +
                assert_equal history, [:start_around_perform], "Only part of around_perform was run"
         
     | 
| 
      
 132 
     | 
    
         
            +
              end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
              class ::AroundPerformJobFailsWhilePerforming
         
     | 
| 
      
 135 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 136 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 137 
     | 
    
         
            +
                  raise StandardError
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
                def self.around_perform_fail_in_yield(history)
         
     | 
| 
      
 140 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 141 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 142 
     | 
    
         
            +
                    yield
         
     | 
| 
      
 143 
     | 
    
         
            +
                  ensure
         
     | 
| 
      
 144 
     | 
    
         
            +
                    history << :ensure_around_perform
         
     | 
| 
      
 145 
     | 
    
         
            +
                  end
         
     | 
| 
      
 146 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 147 
     | 
    
         
            +
                end
         
     | 
| 
      
 148 
     | 
    
         
            +
              end
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
              test "raises an error but may handle exceptions if perform fails" do
         
     | 
| 
      
 151 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 152 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 153 
     | 
    
         
            +
                  perform_job(AroundPerformJobFailsWhilePerforming, history)
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
                assert_equal history, [:start_around_perform, :perform, :ensure_around_perform], "Only part of around_perform was run"
         
     | 
| 
      
 156 
     | 
    
         
            +
              end
         
     | 
| 
      
 157 
     | 
    
         
            +
             
     | 
| 
      
 158 
     | 
    
         
            +
              class ::AroundPerformJobDoesNotHaveToYield
         
     | 
| 
      
 159 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 160 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 161 
     | 
    
         
            +
                end
         
     | 
| 
      
 162 
     | 
    
         
            +
                def self.around_perform_dont_yield(history)
         
     | 
| 
      
 163 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 164 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 165 
     | 
    
         
            +
                end
         
     | 
| 
      
 166 
     | 
    
         
            +
              end
         
     | 
| 
      
 167 
     | 
    
         
            +
             
     | 
| 
      
 168 
     | 
    
         
            +
              test "around_perform is not required to yield" do
         
     | 
| 
      
 169 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 170 
     | 
    
         
            +
                result = perform_job(AroundPerformJobDoesNotHaveToYield, history)
         
     | 
| 
      
 171 
     | 
    
         
            +
                assert_equal false, result, "perform returns false"
         
     | 
| 
      
 172 
     | 
    
         
            +
                assert_equal history, [:start_around_perform, :finish_around_perform], "perform was not run"
         
     | 
| 
      
 173 
     | 
    
         
            +
              end
         
     | 
| 
      
 174 
     | 
    
         
            +
            end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
            context "Resque::Job on_failure" do
         
     | 
| 
      
 177 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
              class ::FailureJobThatDoesNotFail
         
     | 
| 
      
 180 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 181 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 182 
     | 
    
         
            +
                end
         
     | 
| 
      
 183 
     | 
    
         
            +
                def self.on_failure_record_failure(exception, history)
         
     | 
| 
      
 184 
     | 
    
         
            +
                  history << exception.message
         
     | 
| 
      
 185 
     | 
    
         
            +
                end
         
     | 
| 
      
 186 
     | 
    
         
            +
              end
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
              test "it does not call on_failure if no failures occur" do
         
     | 
| 
      
 189 
     | 
    
         
            +
                result = perform_job(FailureJobThatDoesNotFail, history=[])
         
     | 
| 
      
 190 
     | 
    
         
            +
                assert_equal true, result, "perform returned true"
         
     | 
| 
      
 191 
     | 
    
         
            +
                assert_equal history, [:perform]
         
     | 
| 
      
 192 
     | 
    
         
            +
              end
         
     | 
| 
      
 193 
     | 
    
         
            +
             
     | 
| 
      
 194 
     | 
    
         
            +
              class ::FailureJobThatFails
         
     | 
| 
      
 195 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 196 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 197 
     | 
    
         
            +
                  raise StandardError, "oh no"
         
     | 
| 
      
 198 
     | 
    
         
            +
                end
         
     | 
| 
      
 199 
     | 
    
         
            +
                def self.on_failure_record_failure(exception, history)
         
     | 
| 
      
 200 
     | 
    
         
            +
                  history << exception.message
         
     | 
| 
      
 201 
     | 
    
         
            +
                end
         
     | 
| 
      
 202 
     | 
    
         
            +
              end
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
              test "it calls on_failure with the exception and then re-raises the exception" do
         
     | 
| 
      
 205 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 206 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 207 
     | 
    
         
            +
                  perform_job(FailureJobThatFails, history)
         
     | 
| 
      
 208 
     | 
    
         
            +
                end
         
     | 
| 
      
 209 
     | 
    
         
            +
                assert_equal history, [:perform, "oh no"]
         
     | 
| 
      
 210 
     | 
    
         
            +
              end
         
     | 
| 
      
 211 
     | 
    
         
            +
             
     | 
| 
      
 212 
     | 
    
         
            +
              class ::FailureJobThatFailsBadly
         
     | 
| 
      
 213 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 214 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 215 
     | 
    
         
            +
                  raise SyntaxError, "oh no"
         
     | 
| 
      
 216 
     | 
    
         
            +
                end
         
     | 
| 
      
 217 
     | 
    
         
            +
                def self.on_failure_record_failure(exception, history)
         
     | 
| 
      
 218 
     | 
    
         
            +
                  history << exception.message
         
     | 
| 
      
 219 
     | 
    
         
            +
                end
         
     | 
| 
      
 220 
     | 
    
         
            +
              end
         
     | 
| 
      
 221 
     | 
    
         
            +
             
     | 
| 
      
 222 
     | 
    
         
            +
              test "it calls on_failure even with bad exceptions" do
         
     | 
| 
      
 223 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 224 
     | 
    
         
            +
                assert_raises SyntaxError do
         
     | 
| 
      
 225 
     | 
    
         
            +
                  perform_job(FailureJobThatFailsBadly, history)
         
     | 
| 
      
 226 
     | 
    
         
            +
                end
         
     | 
| 
      
 227 
     | 
    
         
            +
                assert_equal history, [:perform, "oh no"]
         
     | 
| 
      
 228 
     | 
    
         
            +
              end
         
     | 
| 
      
 229 
     | 
    
         
            +
            end
         
     | 
| 
      
 230 
     | 
    
         
            +
             
     | 
| 
      
 231 
     | 
    
         
            +
            context "Resque::Job after_enqueue" do
         
     | 
| 
      
 232 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 233 
     | 
    
         
            +
             
     | 
| 
      
 234 
     | 
    
         
            +
              class ::AfterEnqueueJob
         
     | 
| 
      
 235 
     | 
    
         
            +
                @queue = :jobs
         
     | 
| 
      
 236 
     | 
    
         
            +
                def self.after_enqueue_record_history(history)
         
     | 
| 
      
 237 
     | 
    
         
            +
                  history << :after_enqueue
         
     | 
| 
      
 238 
     | 
    
         
            +
                end
         
     | 
| 
      
 239 
     | 
    
         
            +
             
     | 
| 
      
 240 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 241 
     | 
    
         
            +
                end
         
     | 
| 
      
 242 
     | 
    
         
            +
              end
         
     | 
| 
      
 243 
     | 
    
         
            +
             
     | 
| 
      
 244 
     | 
    
         
            +
              test "the after enqueue hook should run" do
         
     | 
| 
      
 245 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 246 
     | 
    
         
            +
                @worker = Resque::Worker.new(:jobs)
         
     | 
| 
      
 247 
     | 
    
         
            +
                Resque.enqueue(AfterEnqueueJob, history)
         
     | 
| 
      
 248 
     | 
    
         
            +
                @worker.work(0)
         
     | 
| 
      
 249 
     | 
    
         
            +
                assert_equal history, [:after_enqueue], "after_enqueue was not run"
         
     | 
| 
      
 250 
     | 
    
         
            +
              end
         
     | 
| 
      
 251 
     | 
    
         
            +
            end
         
     | 
| 
      
 252 
     | 
    
         
            +
             
     | 
| 
      
 253 
     | 
    
         
            +
             
     | 
| 
      
 254 
     | 
    
         
            +
            context "Resque::Job before_enqueue" do
         
     | 
| 
      
 255 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 256 
     | 
    
         
            +
             
     | 
| 
      
 257 
     | 
    
         
            +
              class ::BeforeEnqueueJob
         
     | 
| 
      
 258 
     | 
    
         
            +
                @queue = :jobs
         
     | 
| 
      
 259 
     | 
    
         
            +
                def self.before_enqueue_record_history(history)
         
     | 
| 
      
 260 
     | 
    
         
            +
                  history << :before_enqueue
         
     | 
| 
      
 261 
     | 
    
         
            +
                end
         
     | 
| 
      
 262 
     | 
    
         
            +
             
     | 
| 
      
 263 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 264 
     | 
    
         
            +
                end
         
     | 
| 
      
 265 
     | 
    
         
            +
              end
         
     | 
| 
      
 266 
     | 
    
         
            +
             
     | 
| 
      
 267 
     | 
    
         
            +
              class ::BeforeEnqueueJobAbort
         
     | 
| 
      
 268 
     | 
    
         
            +
                @queue = :jobs
         
     | 
| 
      
 269 
     | 
    
         
            +
                def self.before_enqueue_abort(history)
         
     | 
| 
      
 270 
     | 
    
         
            +
                  false
         
     | 
| 
      
 271 
     | 
    
         
            +
                end
         
     | 
| 
      
 272 
     | 
    
         
            +
             
     | 
| 
      
 273 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 274 
     | 
    
         
            +
                end
         
     | 
| 
      
 275 
     | 
    
         
            +
              end
         
     | 
| 
      
 276 
     | 
    
         
            +
             
     | 
| 
      
 277 
     | 
    
         
            +
              test "the before enqueue hook should run" do
         
     | 
| 
      
 278 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 279 
     | 
    
         
            +
                @worker = Resque::Worker.new(:jobs)
         
     | 
| 
      
 280 
     | 
    
         
            +
                Resque.enqueue(BeforeEnqueueJob, history)
         
     | 
| 
      
 281 
     | 
    
         
            +
                @worker.work(0)
         
     | 
| 
      
 282 
     | 
    
         
            +
                assert_equal history, [:before_enqueue], "before_enqueue was not run"
         
     | 
| 
      
 283 
     | 
    
         
            +
              end
         
     | 
| 
      
 284 
     | 
    
         
            +
             
     | 
| 
      
 285 
     | 
    
         
            +
              test "a before enqueue hook that returns false should prevent the job from getting queued" do
         
     | 
| 
      
 286 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 287 
     | 
    
         
            +
                @worker = Resque::Worker.new(:jobs)
         
     | 
| 
      
 288 
     | 
    
         
            +
                Resque.enqueue(BeforeEnqueueJobAbort, history)
         
     | 
| 
      
 289 
     | 
    
         
            +
                assert_equal 0, Resque.size(:jobs)
         
     | 
| 
      
 290 
     | 
    
         
            +
              end
         
     | 
| 
      
 291 
     | 
    
         
            +
            end
         
     | 
| 
      
 292 
     | 
    
         
            +
             
     | 
| 
      
 293 
     | 
    
         
            +
            context "Resque::Job all hooks" do
         
     | 
| 
      
 294 
     | 
    
         
            +
              include PerformJob
         
     | 
| 
      
 295 
     | 
    
         
            +
             
     | 
| 
      
 296 
     | 
    
         
            +
              class ::VeryHookyJob
         
     | 
| 
      
 297 
     | 
    
         
            +
                def self.before_perform_record_history(history)
         
     | 
| 
      
 298 
     | 
    
         
            +
                  history << :before_perform
         
     | 
| 
      
 299 
     | 
    
         
            +
                end
         
     | 
| 
      
 300 
     | 
    
         
            +
                def self.around_perform_record_history(history)
         
     | 
| 
      
 301 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 302 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 303 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 304 
     | 
    
         
            +
                end
         
     | 
| 
      
 305 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 306 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 307 
     | 
    
         
            +
                end
         
     | 
| 
      
 308 
     | 
    
         
            +
                def self.after_perform_record_history(history)
         
     | 
| 
      
 309 
     | 
    
         
            +
                  history << :after_perform
         
     | 
| 
      
 310 
     | 
    
         
            +
                end
         
     | 
| 
      
 311 
     | 
    
         
            +
                def self.on_failure_record_history(exception, history)
         
     | 
| 
      
 312 
     | 
    
         
            +
                  history << exception.message
         
     | 
| 
      
 313 
     | 
    
         
            +
                end
         
     | 
| 
      
 314 
     | 
    
         
            +
              end
         
     | 
| 
      
 315 
     | 
    
         
            +
             
     | 
| 
      
 316 
     | 
    
         
            +
              test "the complete hook order" do
         
     | 
| 
      
 317 
     | 
    
         
            +
                result = perform_job(VeryHookyJob, history=[])
         
     | 
| 
      
 318 
     | 
    
         
            +
                assert_equal true, result, "perform returned true"
         
     | 
| 
      
 319 
     | 
    
         
            +
                assert_equal history, [
         
     | 
| 
      
 320 
     | 
    
         
            +
                  :before_perform,
         
     | 
| 
      
 321 
     | 
    
         
            +
                  :start_around_perform,
         
     | 
| 
      
 322 
     | 
    
         
            +
                  :perform,
         
     | 
| 
      
 323 
     | 
    
         
            +
                  :finish_around_perform,
         
     | 
| 
      
 324 
     | 
    
         
            +
                  :after_perform
         
     | 
| 
      
 325 
     | 
    
         
            +
                ]
         
     | 
| 
      
 326 
     | 
    
         
            +
              end
         
     | 
| 
      
 327 
     | 
    
         
            +
             
     | 
| 
      
 328 
     | 
    
         
            +
              class ::VeryHookyJobThatFails
         
     | 
| 
      
 329 
     | 
    
         
            +
                def self.before_perform_record_history(history)
         
     | 
| 
      
 330 
     | 
    
         
            +
                  history << :before_perform
         
     | 
| 
      
 331 
     | 
    
         
            +
                end
         
     | 
| 
      
 332 
     | 
    
         
            +
                def self.around_perform_record_history(history)
         
     | 
| 
      
 333 
     | 
    
         
            +
                  history << :start_around_perform
         
     | 
| 
      
 334 
     | 
    
         
            +
                  yield
         
     | 
| 
      
 335 
     | 
    
         
            +
                  history << :finish_around_perform
         
     | 
| 
      
 336 
     | 
    
         
            +
                end
         
     | 
| 
      
 337 
     | 
    
         
            +
                def self.perform(history)
         
     | 
| 
      
 338 
     | 
    
         
            +
                  history << :perform
         
     | 
| 
      
 339 
     | 
    
         
            +
                end
         
     | 
| 
      
 340 
     | 
    
         
            +
                def self.after_perform_record_history(history)
         
     | 
| 
      
 341 
     | 
    
         
            +
                  history << :after_perform
         
     | 
| 
      
 342 
     | 
    
         
            +
                  raise StandardError, "oh no"
         
     | 
| 
      
 343 
     | 
    
         
            +
                end
         
     | 
| 
      
 344 
     | 
    
         
            +
                def self.on_failure_record_history(exception, history)
         
     | 
| 
      
 345 
     | 
    
         
            +
                  history << exception.message
         
     | 
| 
      
 346 
     | 
    
         
            +
                end
         
     | 
| 
      
 347 
     | 
    
         
            +
              end
         
     | 
| 
      
 348 
     | 
    
         
            +
             
     | 
| 
      
 349 
     | 
    
         
            +
              test "the complete hook order with a failure at the last minute" do
         
     | 
| 
      
 350 
     | 
    
         
            +
                history = []
         
     | 
| 
      
 351 
     | 
    
         
            +
                assert_raises StandardError do
         
     | 
| 
      
 352 
     | 
    
         
            +
                  perform_job(VeryHookyJobThatFails, history)
         
     | 
| 
      
 353 
     | 
    
         
            +
                end
         
     | 
| 
      
 354 
     | 
    
         
            +
                assert_equal history, [
         
     | 
| 
      
 355 
     | 
    
         
            +
                  :before_perform,
         
     | 
| 
      
 356 
     | 
    
         
            +
                  :start_around_perform,
         
     | 
| 
      
 357 
     | 
    
         
            +
                  :perform,
         
     | 
| 
      
 358 
     | 
    
         
            +
                  :finish_around_perform,
         
     | 
| 
      
 359 
     | 
    
         
            +
                  :after_perform,
         
     | 
| 
      
 360 
     | 
    
         
            +
                  "oh no"
         
     | 
| 
      
 361 
     | 
    
         
            +
                ]
         
     | 
| 
      
 362 
     | 
    
         
            +
              end
         
     | 
| 
      
 363 
     | 
    
         
            +
            end
         
     |