I have Sidekiq up and running on a RoR application. All works great and jobs are queued up.
I have seen a lot of patterns as far as queuing up jobs but am curios about this pattern which I see in production and works well. It is idempotent, can work with multiple Sidekiq workers and the generate method does the magic....
Any opinions on whether this is a good pattern to use...?
class MailerDeamon include Sidekiq::Worker
def perform(id)
# idempotent
email = Email::Message.find_by(id: id)
return unless email
return unless email.sent? # or something that marks it has been sent
email.begin_transmission!
end
def self.generate
Email::Message.triggered(60).ids.each do |id|
perform_async(id)
end
end
end
Thank you