Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ActiveJob #50

Open
14 tasks
zaratan opened this issue Aug 13, 2018 · 0 comments
Open
14 tasks

Add ActiveJob #50

zaratan opened this issue Aug 13, 2018 · 0 comments
Assignees
Labels
8 Good practice Make your overall project better Project Something about the project

Comments

@zaratan
Copy link

zaratan commented Aug 13, 2018

Why ?

Sending an email (see ticket #46) with Sendgrid take 1 to 2 sec each time. The user doesn't need to wait and the email can be sent asynchronously.

Must have

  • Sidekiq must be configured to work with ActiveJob
  • All emails should be delivered later through Sidekiq/ActiveJob
  • Plug it in Heroku
  • If you have it make it work in Docker

Todo

  • Configure sidekiq to work with active record (in dev) (see documentation lower)
  • For processing emails with sidekiq dont forget to tell sidekiq that you want to process the mailer queue (-q default -q mailers)
  • Email sent by devise token auth are sent with a deliver_now. To send them through sidekiq, define this in the User model:
def send_devise_notification(notification, *args)
  devise_mailer.send(notification, self, *args).deliver_later
end
  • A worker and the main rails process doesn't share a SQL Transaction. So if you sent the emails in an after_create, you might have some fun and your worker might not find the invitation. Use after_commit instead (cf doc lower).
  • To test and NOT use the sidekiq queue add at the end of your rails_helper.rb:
ActiveJob::Base.queue_adapter = :test
  • When it's working in dev the fun part begin: Add Redis as an add-on to all of your heroku apps
  • Add a worker line in your profile to launch sidekiq
  • Each worker will connect to the DB and the number of connection is limited in a free heroku postgresql so limit the number of sidekiq workers to 10 (-c 10)
  • Try your heroku config with heroku local worker (more info on this here: https://devcenter.heroku.com/articles/heroku-local)
  • Deploy in staging and test it, then deploy in production.

Reading List

@zaratan zaratan added Project Something about the project Good practice Make your overall project better 8 labels Aug 13, 2018
@zaratan zaratan self-assigned this Aug 28, 2018
@ThibautGrx ThibautGrx self-assigned this Sep 6, 2018
@showner showner self-assigned this Sep 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8 Good practice Make your overall project better Project Something about the project
Projects
None yet
Development

No branches or pull requests

3 participants