lib/sidekiq.rb in sidekiq-3.5.4 vs lib/sidekiq.rb in sidekiq-4.0.0.pre1

- old
+ new

@@ -108,15 +108,29 @@ yield @client_chain if block_given? @client_chain end def self.server_middleware - @server_chain ||= Processor.default_middleware + @server_chain ||= default_server_middleware yield @server_chain if block_given? @server_chain end + def self.default_server_middleware + require 'sidekiq/middleware/server/retry_jobs' + require 'sidekiq/middleware/server/logging' + + Middleware::Chain.new do |m| + m.add Middleware::Server::Logging + m.add Middleware::Server::RetryJobs + if defined?(::ActiveRecord::Base) + require 'sidekiq/middleware/server/active_record' + m.add Sidekiq::Middleware::Server::ActiveRecord + end + end + end + def self.default_worker_options=(hash) @default_worker_options = default_worker_options.merge(hash.stringify_keys) end def self.default_worker_options @@ -137,20 +151,10 @@ def self.logger=(log) Sidekiq::Logging.logger = log end - # When set, overrides Sidekiq.options[:average_scheduled_poll_interval] and sets - # the average interval that this process will delay before checking for - # scheduled jobs or job retries that are ready to run. - # - # See sidekiq/scheduled.rb for an in-depth explanation of this value - def self.poll_interval=(interval) - $stderr.puts "DEPRECATION: `config.poll_interval = #{interval}` will be removed in Sidekiq 4. Please update to `config.average_scheduled_poll_interval = #{interval}`." - self.options[:poll_interval_average] = interval - end - # How frequently Redis should be checked by a random Sidekiq process for # scheduled and retriable jobs. Each individual process will take turns by # waiting some multiple of this value. # # See sidekiq/scheduled.rb for an in-depth explanation of this value @@ -180,9 +184,18 @@ def self.on(event, &block) raise ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol) raise ArgumentError, "Invalid event name: #{event}" unless options[:lifecycle_events].key?(event) options[:lifecycle_events][event] << block end + + # We are shutting down Sidekiq but what about workers that + # are working on some long job? This error is + # raised in workers that have not finished within the hard + # timeout limit. This is needed to rollback db transactions, + # otherwise Ruby's Thread#kill will commit. See #377. + # DO NOT RESCUE THIS ERROR IN YOUR WORKERS + class Shutdown < Interrupt; end + end require 'sidekiq/extensions/class_methods' require 'sidekiq/extensions/action_mailer' require 'sidekiq/extensions/active_record'