I have an app that serves up many complex JSON pieces. Some of these could hit the database 1000 times. I pre-cache the results in our db such that when we change the underlying data we regenerate the JSON frag which then gets stored in the DB. I am using Sidekiq to manage this. One issue is that if I put this cache killing code into a Rails Model callback, I could potentially get multiple copies of the worker request at once. This is obviously not what I want. Is there a way in Sidekiq to say only add this to queue if it currently is not in the queue?
Here's an example of what I'm doing:
class ArcBackground
include Sidekiq::Worker
def perform(id)
Menu.regenerateMenuJSON(id)
Menu.regenerateMenuJSONFull(id)
end
end