I have a rails application in which I have a function that sends a lot of emails. I would like to do this asynchronously , and I thought the deliver_later method would do this. I currently have some delay when the user clicks submit until the form is submitted, which leads to a bad user experience (this is a pretty simple form). My implementation is as follows:
def create respond_to do |format| if @competition.save [...] send_notification_to_team_members end end def send_notification_to_team_members @team.members.each do |member| unless member.user.eql?(current_user) Mailer.deliver_new_competition_notification(member.user, @competition).deliver_later end end end
Currently, it takes ~ 4 seconds to complete the action. I also tried:
Mailer.deliver_new_competition_notification(member.user, @competition).deliver_later(wait: 1.minute)
Then it will take even more time - I would rate ~ 1 minute.
So, I am using deliver_later incorrectly, or a method that does not fulfill what I expect. In this case, is there any other way that I can use to improve my work?
source share