LoginSignup
0
0

More than 5 years have passed since last update.

Resqueのenqueueの処理

Posted at

@redis.pipelinedで突っ込んでいた

/lib/resque.rb#L352-L354

  def enqueue(klass, *args)
    enqueue_to(queue_from_class(klass), klass, *args)
  end

/lib/resque.rb#L365-L379

  def enqueue_to(queue, klass, *args)
    # Perform before_enqueue hooks. Don't perform enqueue if any hook returns false
    before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook|
      klass.send(hook, *args)
    end
    return nil if before_hooks.any? { |result| result == false }

    Job.create(queue, klass, *args)

    Plugin.after_enqueue_hooks(klass).each do |hook|
      klass.send(hook, *args)
    end

    return true
  end

/lib/resque/job.rb#L87-L97

    def self.create(queue, klass, *args)
      Resque.validate(klass, queue)

      if Resque.inline?
        # Instantiating a Resque::Job and calling perform on it so callbacks run
        # decode(encode(args)) to ensure that args are normalized in the same manner as a non-inline job
        new(:inline, {'class' => klass, 'args' => decode(encode(args))}).perform
      else
        Resque.push(queue, :class => klass.to_s, :args => args)
      end
    end

/lib/resque.rb#L270-L272

  def push(queue, item)
    data_store.push_to_queue(queue,encode(item))
  end

/lib/resque/data_store.rb#L102-L107

      def push_to_queue(queue,encoded_item)
        @redis.pipelined do
          watch_queue(queue)
          @redis.rpush redis_key_for_queue(queue), encoded_item
        end
      end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0