I am using Sidekiq for some of my background processes.
Currently what I do is:
start bundle exec rails s on one terminal and then start bundle exec sidekiq on a different terminal so that the sidekiq starts itself and look for jobs to process.
What I want is:
As soon as i start bundle exec rails s it should also start the sidekiq bundle exec sidekiq. How can i integrate it in just Development environment ??
For apps like yours which require a number of services to be running consider using foreman and a Procfile to define those processes. Then you can use foreman start to run all of them in a single terminal.
Related
I understand that "bundle exec" is directing the bundler to execute something in the context of the given directory and gemfile.
But what is the difference between bundle exec rake and bundle exec rackup?
Also, in the case of bundle exec rackup what is the start of flow of execution?
They are different tools.
rake runs task scripts defined using a special DSL.
rackup is a part of rack which is a minimal webserver interface.
rackup is a useful tool for running Rack applications, which uses the Rack::Builder DSL to configure middleware and build up applications easily.
rackup automatically figures out the environment it is run in, and runs your application as FastCGI, CGI, or WEBrickâall from the same configuration.
To run a Rack application you can pass a path to it as a parameter:
bundle exec rackup yourapp.ru
Or create config.ru file with your application initialization and just run bundle exec rackup.
Here is the minimal Rack application:
run ->(env) { [200, {'Content-Type' => 'text/html'}, ['Hi Mugen']] }
UPD
As #tadman mentioned in a comment below bundle exec just loads what's in the Gemfile and prepared the environment. Also, dependent on your setup you can run rake and rackup without the bundle exec command.
I have a simple web app on heroku running on Passenger and I am trying to make the emails asynchronous. I set it all up with Sidekiq in my dev environment and then I realized I have to start a new dyno on Heroku to run the Sidekiq worker and have to pay $34/m. I am trying to see if I can run Sidekiq on the web dyno with Passenger and save the $34/m cost for now till its worth that investment.
I found a post here that explains how to do this with Unicorn. I am wondering if I can do the same thing with Passenger.
If that doesn't work I will look at using sucker_punch or use unicorn instead but will be good if I can Sidekiq working on the same dyno with Passenger.
I am on rails 3.1, sidekiq 3.1.4 and passenger 4.0.5 - can upgrade here if I have to.
Thanks for your thoughts.
-S
You can. There's no difference between Passenger and Unicorn when it comes to achieving this goal. Instead of specifying web: bundle exec unicorn ... in your Procfile, you just set web: bundle exec passenger in your Procfile. Instead of setting a Unicorn config file, you set equivalent Passenger command line arguments or configuration.
I am using ruby (not rails) and I have install resque gem. According to the manual, I should start the workers using the following command:
resque work
But this command doesn't start the workers at all (I have checked that resque file in bin/ and it doesn't accept 'work' at all).
Here is the output:
Usage: resque [options] COMMAND
Options:
-r, --redis [HOST:PORT] Redis connection string
-N, --namespace [NAMESPACE] Redis namespace
-h, --help Show this message
Commands:
remove WORKER Removes a worker
kill WORKER Kills a worker
list Lists known workers
Created rakefile with:
require "resque/tasks"
and run resque:
rake resque:work QUEUE=*
Is there a way i can start both faye and rails apps together in rainbows/unicorn.
Right now i'm using rainbows to start faye/private_pub app but would like to start rails also with it
Do you know Foreman?
With foreman you can set the commands to start your app on a single file, like this
web: bundle exec start_app_command
faye: bundle exec start_faye_command
and then, just run bundle exec foreman start and foreman will run both rails and faye
How can I run a Rack-based application (not Rails) with unicorn? Let's assume I have a "hello world" response simple rack app with the name of server.ru, and config file at the same directory with the name of unicorn.conf, how am I supposed to run it? In Thin, for example, I would do something like:
bundle exec rackup server.ru -s thin -E production -p 4001
How would I do the same to run under Unicorn?
Unicorn does not give any special treatment to Rails 3+ applications, so the behavior is exactly the same for Rails 3+ applications and non-Rails Rack applications. Just run
unicorn
in your app's root. To run with a specific port, pass -p/--port with the port:
unicorn -p 4001
You can also specify the rackup file:
unicorn server.ru
You can see all the options by running unicorn --help. Of course, you should prepend bundle exec to these commands as needed by your setup.
You can make a setting file for unicorn like this:
working_directory "/path/to/your/app"
listen 4001
pid "/tmp/unicorn.pid"
And then launch unicorn with the following command:
unicorn -c /path/to/your/setting/file.rb