Ruote worked in a rails running on passenger

55 views
Skip to first unread message

emc_lab

unread,
Dec 12, 2013, 10:03:42 PM12/12/13
to openwfe...@googlegroups.com
Hi All,
We have the current setting in window7:  Ruote worker is started within rails on its own thread, all is good. We moved our deployment to a linux box and we are using nginx and passenger to host our rails app. We configured passenge to keep at least 1 instance of a rails app, and therefore not killing the apps and the ruote worker. What we have noticed after some inactivity about 15 minutes, the Ruote.storage_participant.all will retunr no workitems, if I bounce nginx, the sames call will return the workitems. We thought may the passenger config is wrong, but double check (see below) but we also record the ruby pid, prior to the incativty period and after and the ruby pid is the same. Any way you can help us figuring out the issue?.

snippet of the nginx config:

       #biz-tools
       location ~ ^/bt/*$ {
         return 301 /bt/authentify/signin;
         passenger_min_instances 1;
       }

John Mettraux

unread,
Dec 12, 2013, 10:57:59 PM12/12/13
to openwfe...@googlegroups.com

On Thu, Dec 12, 2013 at 07:03:42PM -0800, emc_lab wrote:
>
> We have the current setting in window7: Ruote worker is started within
> rails on its own thread, all is good. We moved our deployment to a linux
> box and we are using nginx and passenger to host our rails app. We
> configured passenge to keep at least 1 instance of a rails app, and
> therefore not killing the apps and the ruote worker.

Hello,

OK, well done with the passenger settings.

> What we have noticed
> after some inactivity about 15 minutes, the Ruote.storage_participant.all
> will retunr no workitems, if I bounce nginx, the sames call will return the
> workitems. We thought may the passenger config is wrong, but double check
> (see below) but we also record the ruby pid, prior to the incativty period
> and after and the ruby pid is the same. Any way you can help us figuring
> out the issue?.
>
> snippet of the nginx config:
>
> #biz-tools
> location ~ ^/bt/*$ {
> return 301 /bt/authentify/signin;
> passenger_min_instances 1;
> }

I'm not a nginx expert, I tend to use "proxy_pass" when I put nginx in front
of Ruby (and Thin).

Does your setup without nginx work?

You should probably add some debug output to the nginx setup (and to the
passenger config as well if possible) to determine if the problem is on the
nginx or the passenger side.

By bouncing Nginx, I guess you mean restarting Nginx. When Nginx returns an
empty result list, does hitting directly passenger return the up-to-date
list?


Good luck,

--
John Mettraux - http://lambda.io/jmettraux

Hartog De Mik

unread,
Dec 13, 2013, 2:07:33 AM12/13/13
to openwfe...@googlegroups.com
Passenger is notoriously know for reaping it's children and forking new ones when the demand rises.

You need to hook in some stuff into passenger to let it re-connect to your database(s)




--
--
you received this message because you are subscribed to the "ruote users" group.
to post : send email to openwfe...@googlegroups.com
to unsubscribe : send email to openwferu-use...@googlegroups.com
more options : http://groups.google.com/group/openwferu-users?hl=en
---
You received this message because you are subscribed to the Google Groups "ruote" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openwferu-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

denis....@bluewaterbrand.com

unread,
Dec 13, 2013, 3:37:16 PM12/13/13
to openwfe...@googlegroups.com
We are using ruote within a Rails 4 app running under Apache and Passenger on Linux.  Originally we started up ruote (dashboard, worker and storage) within the Rails process, but we ran into problems with this approach that we weren't seeing in our local development environments (which is using Webrick instead of Passenger).  We finally opted to move the Ruote worker out to a separate process that is managed independent of the Rails application, and it has been relatively smooth sailing since. 

Here is our solution at a high level, in case this helps if you decide to try something similar:

1. Create the ruote dashboard and storage inside a Rails initializer (i.e. config/initializers/ruote.rb). 

if Rails.env.staging? || Rails.env.production?
  if defined?(PhusionPassenger)
    # Running inside Passenger
    PhusionPassenger.on_event(:starting_worker_process) do | forked |
      if forked
        # Initialize the ruote dashboard and storage here.  Do not initialize the worker here.
      end
    end
  end
end

2. Use the daemons gem to run a separate process that contains a ruote worker.  We patterned our solution after the delayed_job script (i.e. [rails root]/script/delayed_job) that comes with the delayed_job gem.  Pretty much copy/paste/modify.

3. Start up the ruote worker process as part of our Capistrano deploy script using a "before" deploy hook

before "deploy:restart", "ruote:restart"

namespace :ruote do
  desc "Restart the ruote process"
  task :restart, :roles => :app do
    run "mkdir -p #{shared_path}/pids"    # Create a shared_path/pids directory if one does not exist.  This only changes new environments.
    run "cd #{current_path} && RAILS_ENV=#{rails_env} script/ruote restart"
  end
end

Hope this helps,
Denis

emc_lab

unread,
Dec 13, 2013, 10:16:08 PM12/13/13
to openwfe...@googlegroups.com
Thanks everyone for the replies. Will try the suggestions and report back.

emc_lab

unread,
Dec 16, 2013, 10:57:42 PM12/16/13
to openwfe...@googlegroups.com
Hi coffeeaddict:

Do you know what passenger kills and causing problem for ruote worker? Is it db connection to the database killed? The ruote worker starts working again after restarting nginx. Usually after 5min idle time, there will be problem for ruote worker.

Setting up min instances in passenger is not enough to keep ruote worker working.

Best Regards
-emclab

emc_lab

unread,
Dec 17, 2013, 2:52:23 PM12/17/13
to openwfe...@googlegroups.com
Here is the code of ruote.rb in rails app config/initializers/ :

require 'rubygems'
require 'json' # gem install json
require 'ruote'
require 'ruote-sequel' # gem install ruote-sequel
require 'commonx'
require 'logger'
require 'daemons'

#Usage:
# bundle exec ruby ruote_worker.rb sqlite://../biz-tools/db/development.sqlite3

#Default value
# set up ruote storage
db_name = 'sqlite://../biz-tools/db/development.sqlite3'
db_name = ARGV[0] if ARGV[0]
db_name = Commonx::CommonxHelper.find_ruote_config_for('db_name')

#sequel = Sequel.connect('sqlite://../biz-tools/db/development.sqlite3')
sequel = Sequel.connect('sqlite://db/' + db_name)

#ruote_docs is hte table name
opts = { 'sequel_table_name' => 'ruote_docs' }
RUOTE_STORAGE = Ruote::Sequel::Storage.new(sequel, opts)

RUOTE.register do
  eval(Commonx::CommonxHelper.find_ruote_config_for('ruote_participant_register'))
  catchall
end

# let's join the worker thread (prevents the script from exiting)
RUOTE.join



logger = Logger.new('ruote_worker.log')
# set up ruote dashboard and run ruote worker outside of rails app
worker = Ruote::Worker.new("worker", RUOTE_STORAGE)


logger.info("Starting ruote worker...")
worker.run_in_thread()
logger.info("Started ruote worker...")


On Thursday, December 12, 2013 9:03:42 PM UTC-6, emc_lab wrote:
Reply all
Reply to author
Forward
0 new messages