lib/backburner/worker.rb in backburner-allq-1.0.47 vs lib/backburner/worker.rb in backburner-allq-1.0.48

- old
+ new

@@ -25,25 +25,29 @@ # @raise [Beaneater::NotConnected] If beanstalk fails to connect. # @example # Backburner::Worker.enqueue NewsletterSender, [self.id, user.id], :ttr => 1000 # def self.enqueue(job_class, args = [], opts = {}) + options = opts.dup + # Invoke Procs if they are sent - opts.each_key do |k| - opts[k] = opts[k].call job_class, args if opts[k].instance_of?(Proc) + options.each_key do |k| + if options[k].instance_of?(Proc) + options[k] = options[k].call job_class, args + end end - opts[:shard_key] = opts[:shard_key].nil? ? 'X' : opts[:shard_key].to_s - pri = resolve_priority(opts[:pri] || job_class) - delay = [0, opts[:delay].to_i].max - ttr = resolve_respond_timeout(opts[:ttr] || job_class) + options[:shard_key] = options[:shard_key].nil? ? 'X' : options[:shard_key].to_s + pri = resolve_priority(options[:pri] || job_class) + delay = [0, options[:delay].to_i].max + ttr = resolve_respond_timeout(options[:ttr] || job_class) res = Backburner::Hooks.invoke_hook_events(job_class, :before_enqueue, *args) return nil unless res # stop if hook is false data = { class: job_class.name, args: args, ttr: ttr } - queue = opts[:queue] && (opts[:queue].is_a?(Proc) ? opts[:queue].call(job_class) : opts[:queue]) + queue = options[:queue] && (options[:queue].is_a?(Proc) ? options[:queue].call(job_class) : options[:queue]) begin response = nil connection = Backburner::Connection.new(Backburner.configuration.allq_url) connection.retryable do @@ -52,11 +56,11 @@ send_data = { pri: pri, delay: delay, ttr: ttr } - opts.merge!(send_data) - response = connection.put(tube_name, serialized_data, opts) + options.merge!(send_data) + response = connection.put(tube_name, serialized_data, options) end return nil unless Backburner::Hooks.invoke_hook_events(job_class, :after_enqueue, *args) ensure connection.close if connection end