简体   繁体   中英

How can I send email after 3 minutes in Rails using Sidekiq?

I have a simple rails app. When a user(current_user) create a property, I want that an email will be sent to admin. Mailing is working fine, but i don't have idea how to send the email after delaying 3 minutes. Using sidekiq is must here.

Mailer:

 class PropertyMailer < ActionMailer::Base
   def property_created(user)
     mail(
       to: "admin@tgmalim-directory.com",
       from: user.email,
       subject: "Property submitted",
       body: "A property has been submitted. Please review it."
      )
   end
 end

PropertiesController:

def create
 @property = current_user.properties.build(property_params)

 respond_to do |format|
  if @property.save
    
    SendEmailToAdminJob.perform_later
    
    format.html { redirect_to @property, notice: "Property was successfully saved." }
    format.json { render :show, status: :created, location: @property }
  else
    format.html { render :new, status: :unprocessable_entity }
    format.json { render json: @property.errors, status: :unprocessable_entity }
  end
end

end

SendEmailToAdmin Job:

 class SendEmailToAdminJob < ApplicationJob
   queue_as :default

   def perform(*args)

   end
 end

Thanks in advance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM