Skip to content

Instantly share code, notes, and snippets.

View flaviokr's full-sized avatar

Flávio Kon Rosenfeld flaviokr

View GitHub Profile
# If you want to provide a maximum queue size, you may also consider the fallback_policy which defines what will
# happen if work is posted to a pool when the queue of waiting work has reached the maximum size and no new threads
# can be created. Available policies:
# abort: Raise a Concurrent::RejectedExecutionError exception and discard the task. (default policy)
# discard: Silently discard the task and return nil as the task result.
# caller_runs: The work will be executed in the thread of the caller, instead of being given to another thread in the pool.
pool = Concurrent::ThreadPoolExecutor.new(
:min_threads => [2, Concurrent.processor_count].max,
# para mover da fila low para pending
q_from = "low"
q_to = "pending"
count_block = proc{ Sidekiq.redis { |conn| conn.llen("queue:#{q_from}") } }
while count_block.call > 0 do
Sidekiq.redis { |conn| conn.rpoplpush "queue:#{q_from}", "queue:#{q_to}" }
end
# para recuperar os jobs da fila pending
# verificar se todos os jobs são da mesma classe
@flaviokr
flaviokr / sidekiq_api_reference.rb
Last active January 3, 2018 18:40
Sidekiq API Reference
Sidekiq.redis { |conn| conn.flushdb } # clear everything
Sidekiq::Queue.all # get all queues
Sidekiq::Queue.new # get the "default" queue
Sidekiq::Queue.new("mailer") # get the "mailer" queue
Sidekiq::Queue.new.clear # deletes all jobs in a queue, by removing the queue
Sidekiq::Queue.all.each(&:clear) # deletes all jobs in all queues
ss = Sidekiq::ScheduledSet.new
ss.size