Created
May 15, 2009 16:08
-
-
Save nicolasblanco/112273 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DOC : | |
| Workling / Starling | |
| Workling / Starling | |
| How to use/test Workling / Starling in development mode (ONLY) ? | |
| First, install the gems : | |
| $> sudo gem install eventmachine memcache-client | |
| $> sudo gem install starling-starling --source http://gems.github.com | |
| Create Starling pool… | |
| $> sudo mkdir /var/spool/starling | |
| Launch starling in a tab of your terminal… | |
| $> sudo starling | |
| Password: | |
| Starting at 127.0.0.1:22122. | |
| I, [2009-04-24T16:49:38.996451 #26348] INFO -- : Starling STARTUP on 127.0.0.1:22122 | |
| Check that Starling is launched on the good port number! | |
| Now, in the project directory… Launch Workling Client. | |
| $> ./script/workling_client start | |
| Check log/workling.output, it should BE like this : | |
| $> cat log/workling.output | |
| => Loading Rails... | |
| FiveRuns Manage (1.1.1): Rails version (2.2.2) is supported | |
| ** Rails loaded. | |
| ** Starting Workling::Remote::Invokers::ThreadedPoller... | |
| ** Use CTRL-C to stop. | |
| If it is not like this : IT WON’T WORK. Find out why before going on..! | |
| Now Workling / starling should work on Keldelice! | |
| Stop workling Client | |
| Easy… | |
| $> ./script/workling_client stop | |
| Testing your Workling / Starling installation | |
| IMPORTANT NOTE 1 : Workling DOES NOT work with Mongrel (because it is not evented !). You have to use Thin. | |
| To install Thin : | |
| sudo gem install thin | |
| To start the project using Thin : | |
| ./script/server thin | |
| You should look for the following lines when the server starts : | |
| ... | |
| => Booting Thin (use 'script/server webrick' to force WEBrick) | |
| => Rails 2.2.2 application starting on http://0.0.0.0:3000 | |
| => Ctrl-C to shutdown server | |
| >> Using rails adapter | |
| ... | |
| >> Thin web server (v1.0.0 codename That's What She Said) | |
| >> Maximum connections set to 1024 | |
| ... | |
| IMPORTANT NOTE 2 : You should start Workling Client AFTER launching your server. After launching the client, look for the following lines IN the server log output : | |
| ... | |
| Discovered listener DataImportWorker | |
| Listener thread DataImportWorker started | |
| Discovered listener HighriseWorker | |
| Listener thread HighriseWorker started | |
| Discovered listener TestingWorker | |
| Listener thread TestingWorker started | |
| ... | |
| If everything is OK, there is a test URL to test your installation : | |
| http://localhost:3000/welcome/worker_test | |
| The output should be like this : | |
| Hello ! Time is 27 avril 2009 à 16:50, Rails env is development, rand test file file name is /tmp/test_961. | |
| The number of the rand test file is… random ;). Now look for this file with “cat”. The worker should add a ” . ” character every second for 15 seconds. If the file exists and contains 15 ., congrats, your workling/starling works! You can now relax and have a big coffee!. | |
| Un worker de test : | |
| class TestingWorker < Workling::Base | |
| def this_is_a_test(options) | |
| File.open(options[:id], "w") { |f| 1.upto(30) { f.write "."; f.flush; sleep(1) } } | |
| end | |
| end | |
| L'appel du worker test dans un controleur : | |
| def worker_test | |
| raise ActiveRecord::RecordNotFound unless logged_in? && current_user.admin? | |
| file_name = "/tmp/test_#{rand(1000)}" | |
| TestingWorker.asynch_this_is_a_test(:id => file_name) | |
| render :text => "Hello ! Time is #{Time.now}, Rails env is #{Rails.env}, rand test file file name is #{file_name}." | |
| end | |
| Notre tache sky rake pour workling : | |
| namespace :sky do | |
| namespace :workling do | |
| namespace :client do | |
| desc "Starts workling client" | |
| task :start, :roles => :app, :only => { :primary => true } do | |
| run "sudo -u #{sky_app_user} bash -c 'cd #{current_path} && export RAILS_ENV=#{rails_env} && ./script/workling_client stop'" | |
| run "sudo -u #{sky_app_user} bash -c 'cd #{current_path} && rm -f log/workling.output'" | |
| run "sudo -u #{sky_app_user} bash -c 'cd #{current_path} && export RAILS_ENV=#{rails_env} && ./script/workling_client start'" | |
| end | |
| desc "Stops workling client" | |
| task :stop, :roles => :app, :only => { :primary => true } do | |
| run "sudo -u #{sky_app_user} bash -c 'cd #{current_path} && export RAILS_ENV=#{rails_env} && ./script/workling_client stop'" | |
| end | |
| end | |
| namespace :starling do | |
| task :starling_setup, :roles => :app, :only => { :primary => true } do | |
| # Create pool directory for Starling | |
| run "#{sudo} mkdir -p /var/spool/starling" | |
| end | |
| desc "Starts Starling server" | |
| task :start, :roles => :app, :only => { :primary => true } do | |
| run "#{sudo} starling -d -h 0.0.0.0 -p 15151" | |
| end | |
| desc "Stops Starling server" | |
| task :stop, :roles => :app, :only => { :primary => true } do | |
| starling = capture "starling_top -p 15151" | |
| starling_pid = YAML.load(starling)["pid"] | |
| puts "Killing Starling, pid : #{starling_pid}" | |
| run "#{sudo} kill #{starling_pid}" | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment