0

I have a Ruby on Rails 5.2.3 app that uses ActiveJob to run a background job that sends an email to users upon registration. In development I run bundle exec rake jobs:work to start the process. I have my app hosted on DigitalOcean using their Marketplace image which includes a systemd service. This is the systemd service file:

/etc/systemd/system/rails.service
[Unit]
Description=appname
Requires=network.target

[Service]
Type=simple
Environment="RAILS_ENV=production"
User=rails
Group=rails
WorkingDirectory=/home/rails/appname/current
ExecStart=/bin/bash -lc 'bundle exec puma'
TimeoutSec=30s
RestartSec=30s
Restart=always

[Install]
WantedBy=multi-user.target

I've read through the answers to this question but I am still not too sure what to do. Should I create multiple services to run the application and the jobs? Or is there a way to get them to run from the same file in parallel (I'm assuming that this type of service needs to be run in parallel)?

Derek C
  • 323
  • 3
  • 13
  • do u use sidekiq ??? – Abhishek Aravindan Jul 19 '19 at 09:08
  • Nope, just using ActiveJob. Would I need to use Sidekiq too? It's quite a small app so I don't wanna make it too complicated. The background job will only be used to the mailers. – Derek C Jul 19 '19 at 09:10
  • Could I maybe do something like this: ```ExecStartPost=/home/rails/appname/current 'bundle exec rake jobs:work'```? And change the service type to ```forking```? – Derek C Jul 19 '19 at 09:11
  • do u use one-click rails application droplet in digital ocean??? – Abhishek Aravindan Jul 19 '19 at 09:14
  • Yes, that's the droplet I'm using. – Derek C Jul 19 '19 at 09:15
  • sidekiq makes this easy ... thats why i chose to use it.... – Abhishek Aravindan Jul 19 '19 at 09:16
  • I'll do some research and see how to do it with Sidekiq – Derek C Jul 19 '19 at 09:39
  • Will Sidekiq start automatically when Puma is started? Because at the moment my background job works, I just need to have it run automatically. And if I change a job will I need to restart Sidekiq? Or can I just restart the rails service and it will restart too? – Derek C Jul 19 '19 at 09:44
  • it will automatically restart when ur app deployed – Abhishek Aravindan Jul 19 '19 at 09:52
  • Awesome, will have a look at it :) – Derek C Jul 19 '19 at 10:00
  • 1
    i wrote a blog how to do it. http://www.enquerer.com/run-sidekiq-in-digital-ocean-production-droplet-for-capistrano-deployed-rails-application/ – Abhishek Aravindan Jul 19 '19 at 10:44
  • Looks like you're still using a systemd service to run Sidekiq. Wouldn't it be better for me to just create another service instead since my background job already works. There will be at most 5-10 registrations per month and concurrent users will be probably under 10 at any given time. It seems like a bit of over kill to install Redis and Sidekiq. I'll definately look into it for larger apps though... – Derek C Jul 19 '19 at 11:09

0 Answers0