I'm currently building an admin dashboard to monitor our SQS queues, inspired by this medium post.
I managed to have everything working fine with this code in my custom shoryuken middelware :
class DashboardMiddleware
def call(worker_instance, queue, sqs_msg, body)
redis = Redis.new(url: ENV['REDIS_DASHBOARD_URL'])
check_if_already_failed(redis, sqs_msg.attributes['SentTimestamp'].to_i)
redis.incr("sqs-dashboard-enqueued")
yield
redis.incr("sqs-dashboard-consumed")
rescue Exception => e
data = {
id: sqs_msg.attributes['SentTimestamp'].to_i,
worker: worker_instance.class.to_s,
queue: queue,
error: e,
attributes: sqs_msg.attributes,
receipt_handle: sqs_msg.receipt_handle,
body: body,
enqueued_at: Time.at(sqs_msg.attributes['SentTimestamp'].to_i / 1000)
}.to_json
redis.lpush("sqs-dashboard-failures", data)
raise e
end
def check_if_already_failed(redis, job_id)
jobs = redis.lrange("sqs-dashboard-failures", 0, -1).map { |job| JSON.parse(job) }
i = 0
g = nil
jobs.each do |j|
g = i if j["id"] == job_id
i += 1
end
unless g.nil?
redis.lset("sqs-dashboard-failures", g, "DELETED")
redis.lrem("sqs-dashboard-failures", 1, "DELETED")
end
end
end
So i display all my failed jobs in my admin dashboard, and details about the error. That was first step. Now i would like to be able to retry manually thoses jobs (one at the time to begin with). I've been searching around the web for a long time now, and didn't find anything to do that (with shoryuken or directly with sqs sdk).
Does anyone have a clue to manually retry a failed message ? We already gave a look at dead-letter queues, but we would prefer not to use them.
Thanks a lot for any tips or starting point :)