Skip to content

Instantly share code, notes, and snippets.

@manoelneto
Created July 28, 2018 13:47
Show Gist options
  • Save manoelneto/6f780b3aea2455fcc26cfb604f95677b to your computer and use it in GitHub Desktop.
Save manoelneto/6f780b3aea2455fcc26cfb604f95677b to your computer and use it in GitHub Desktop.
require "redis_batch_push"
require "redis"
require_relative "my_sidekiq_worker"
queue = "webhooks"
redis = Redis.new
# numero maximo de escuta por mensagens
max_interval_sec = 30
# número máximo de mensagens a enviar de uma vez
max_size = 1000
runner = RedisBatchPush::Runner.new(redis, queue, max_size, max_interval_sec)
runner.run do |data|
# como o webhooks_controller salva a mensagem em json,
# isso é um array de json, então devemos fazer o parser em cada
# mensagem
data = data.map do |d|
JSON.parse d
end
WebhookSidekiq.perform_async data.to_json
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment