how to start sidekiq automatically on localhost - ruby-on-rails

I have a Rails app which uses a Procfile to start sidekiq automatically on heroku. I'd like it to start sidekiq automatically on localhost (I currently just 'bundle exec sidekiq' in a separate window). Here's my procfile:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec sidekiq
How would I do this? I do have foreman installed locally

You can create a Procfile.dev file that's meant to be used in development. To use it, just do 'foreman start -f Procfile.dev' from the terminal. Passing the -f option allows you to set the path the Procfile to use.
By the way, would probably be good to gitignore your Procfile.dev, as well. That way, others in your team could have their own Procfile.dev.
Hope that helps!

Related

Autostart sidekiq on app boot (RoR)

i'm using sidekiq in a rails DEVELOPMENT environment with rvm and passenger.
At app's boot, i need to manually start Sidekiq with:
bundle exec sidekiq --environment development -C sidekiq.yml
is ther a way to Autostart it on App start or restart (not server boot) ?
thanks
Use the foreman gem. With foreman, you declare all the processes your app requires to run in a Procfile.
See a sample Procfile definition of an app using puma and sidekiq below:
web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq --environment development -C sidekiq.yml
The foreman start command starts your app.

Heroku Delayed Job and Sidekiq in the Same app

I am currently running delayed::job on my Heroku instance for quite a few different types of jobs (exporting large lists etc.) and I'm using the awesome progress job gem that shows a progress bar of the job to the user who made the request.
I'd like to be able to run a sidekiq worker as well for other jobs, not involving the user, that I don't need a progress bar for, because of it's obvious memory improvements over Delayed::Job.
Is it possible for me to run both delayed job and sidekiq on the same heroku app? If so is there any examples I can follow? I'm confused on how I would setup the procfile or this.
Below is my Procfile. I don't see how to start both Delayed Job and Sidekiq? If I do something like just add bundle exec sidekiq on a worker line below, it seems to replace delayed job?
Procfile:
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
web: bundle exec puma -C config/puma.rb
worker: bundle exec rake jobs:work
It is possible.
First, You should solve similar interfaces conflict problem like .delay. here: Run Delayed Jobs and Sidekiq at the same time
Second, you should set multiple active_job adapter configuration. here: http://edgeguides.rubyonrails.org/active_job_basics.html#backends
About Procfile, You can register multiple worker
For example)
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -C config/puma.rb
worker: bundle exec sidekiq
delayedjobworker: bundle exec rake jobs:work
Check https://devcenter.heroku.com/articles/procfile#more-process-type-examples

private_pub with Puma on heroku

I'm trying to deploy my production app on Heroku. I'm using both private_pub and Puma in my app.
I wanted to start both using this procfile :
web: bundle exec puma -C config/puma.rb
web: bundle exec rackup private_pub.ru -s thin -p $PORT -E production
But it fails, it seems like you can have only one web process running at a time on Heroku apps. Is there a way to initialize both ?
ok, so basically you cannot run the 2 processes on heroku at the same time. An easy alternative is to create a dedicated heroku app which sole purpose will be to maintain the Pubsub server running. To do so, just follow this tutorial

Faye server not started by foreman

I am trying to start faye with foreman. My procfile lookd like this:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
worker: bundle exec sidekiq
redis: bundle exec redis-server
faye: bundle exec rackup faye.ru -s thin -E production
When I run bundle exec foreman start
the web, worker and redis servers all start correctly, but not the faye server.
In the console I get: 10:53:56 faye.1 | started with pid 10907
and then nothing more from faye.
If I run the faye server using the command in the procfile: bundle exec rackup faye.ru -s thin -E production, faye starts correctly. What am I doing wrong?
When you run this locally:
bundle exec rackup faye.ru -s thin -E production
rackup will use it's default port, which is 9292.
When it's run on Herkou, it may not start if that port is already in use. Heroku dynamically assigns the $PORT variable to a valid free port as far as I am aware.
My guess is that Faye is either starting on a different port or not starting at all.
It looks like faye is running OK. Try to visit http://localhost:{PORT}/faye.js to see if it's responding. It should come back with JS. Make sure you use the right port when calling faye server. Once you start making requests you should see faye logs being spit by foreman.
This is Foreman's missing output issue.
If you are not seeing any output from your program, there is a likely chance that it is buffering stdout. Many languages such as Ruby and Python buffer stdout by default.
Faye doesn't set $stdout.sync = true and therefore its output is missing.
I've had the same issue some time ago and tried to fix it but my pull request was rejected.

Heroku rails Procfile

I am very new to Heroku.
I uploaded my Rails app to Heroku and would like to run it with Thin instead of Webrick. Following Heroku’s guide I am supposed to use web: bundle exec rails server thin -p $PORT -e $RACK_ENV to create the procfile. However I always get the response web:: command not found.
What am I missing?
You’re not supposed to run web: bundle exec rails server thin -p $PORT -e $RACK_ENV as a command, rather you create a new file called Procfile with that as its contents.
Either create the file and paste it in using your editor, or just do:
echo "web: bundle exec rails server thin -p \$PORT -e \$RACK_ENV" > Procfile
Have you bundled thin into your application?
gem 'thin'
If not, you're looking at Rails trying to use the default server. Personally, I would look at using Unicorn on Heroku, but be careful with how many workers you might need.
http://neilmiddleton.com/the-procfile-is-your-friend. Cached version: https://web.archive.org/web/20130926005616/http://www.neilmiddleton.com/the-procfile-is-your-friend
http://neilmiddleton.com/getting-more-from-your-heroku-dynos

Resources