Search code examples
ruby-on-railsrubyherokuheroku-postgres

Background jobs on heroku


I am brand new to Heroku and I am going through the tutorials for a Rails app.

Right now all it does is process some background jobs with sidekiq. The only frontend component is the Sidekiq dashboard.

It says to start the web server in the Procfile. But since all I'll need to do is have a worker scheduled to run my background jobs at certain intervals, does that mean I can just not initiate the web server unless I want to look at the queuing dashboard? As long as I have the other stuff in rake tasks, I should be able to leave the web server off, right?

Also, I noticed that when you push your code to Heroku, it doesn't automatically migrate the DB. If I wanted to ensure the db is up to date each time, would I put that in the Procfile too?


Solution

  • You are correct for running only Sidekiq and not the web server, you can make procfile like this:

    worker: bundle exec sidekiq -C config/sidekiq.yml
    

    This Procfile command will start the Sidekiq process but won't initiate the web server. As you mentioned, this setup is sufficient for processing background jobs.

    while for database migrations on Heroku after each deployment, you can indeed automate this process using release phase scripts in your Procfile

    release: bundle exec rake db:migrate
    

    By including the release command in your Procfile, Heroku will automatically run rake db:migrate after each deployment, ensuring that the database schema is up-to-date.

    so this is your final Procfile looks like that

    release: bundle exec rake db:migrate
    worker: bundle exec sidekiq -C config/sidekiq.yml