Skip to content
Browse files

Initial commit of app

  • Loading branch information...
1 parent 5039818 commit bcfd2f1627244b4d29774234eb6f61ed85c7bda1 Jennifer Hickey committed Apr 27, 2012
Showing with 228 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +5 −0 Gemfile
  3. +33 −0 Gemfile.lock
  4. +71 −1 README.md
  5. +8 −0 Rakefile
  6. +38 −0 app.rb
  7. +19 −0 config.ru
  8. +22 −0 job.rb
  9. +14 −0 server-manifest.yml
  10. +17 −0 worker-manifest.yml
View
1 .gitignore
@@ -0,0 +1 @@
+vendor
View
5 Gemfile
@@ -0,0 +1,5 @@
+source "http://rubygems.org"
+gem 'sinatra'
+gem 'resque'
+gem 'rake'
+gem 'json'
View
33 Gemfile.lock
@@ -0,0 +1,33 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ json (1.6.5)
+ multi_json (1.1.0)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rake (0.9.2.2)
+ redis (2.2.2)
+ redis-namespace (1.0.3)
+ redis (< 3.0.0)
+ resque (1.20.0)
+ multi_json (~> 1.0)
+ redis-namespace (~> 1.0.2)
+ sinatra (>= 0.9.2)
+ vegas (~> 0.1.2)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ tilt (1.3.3)
+ vegas (0.1.11)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ json
+ rake
+ resque
+ sinatra
View
72 README.md
@@ -1,4 +1,74 @@
resque-sample
=============
-Copy of &quot;demo&quot; example from resque code. Made to work on Cloud Foundry.
+Copy of [resque demo sample](https://github.com/defunkt/resque/tree/master/examples/demo) that can be deployed on Cloud Foundry.
+This app differs from the original only by addition of the Gemfile and Cloud Foundry manifest files.
+Highlights CF Ruby auto-reconfiguration by automatically connecting the server and workers to a CF Redis service.
+
+### Starting the Demo App
+
+Here's how to deploy the Sinatra app to Cloud Foundry:
+
+ $ bundle install
+ $ bundle package
+ $ vmc push --manifest server-manifest.yml
+ Would you like to deploy from the current directory? [Yn]:
+ Application Name: my-resque-server
+ Application Deployed URL [my-resque-server.cloudfoundry.com]:
+ $ open http://my-resque-server.cloudfoundry.com
+
+Click 'Create New Job' a few times. You should see the number of
+pending jobs rising.
+
+
+### Starting the Demo Worker
+
+Deploy the worker on Cloud Foundry:
+
+ $ vmc push --manifest worker-manifest.yml
+ Would you like to deploy from the current directory? [Yn]:
+ Application Name: my-resque-worker
+ $ vmc logs my-resque-worker
+
+You should see the following output:
+
+ *** Starting worker 5fa7867f-b1ce-4b01-bf64-3af799439f72:6825:default
+ *** got: (Job{default} | Demo::Job | [{}])
+ Processed a job!
+ *** done: (Job{default} | Demo::Job | [{}])
+
+You can also edit the command property in worker-manifest.yml to use `VVERBOSE` (very verbose) if you want to see more:
+
+ $ VVERBOSE=true QUEUE=default rake resque:work
+ *** Starting worker hostname:90399:default
+ ** [05:55:09 2009-09-16] 90399: Registered signals
+ ** [05:55:09 2009-09-16] 90399: Checking default
+ ** [05:55:09 2009-09-16] 90399: Found job on default
+ ** [05:55:09 2009-09-16] 90399: got: (Job{default} | Demo::Job | [{}])
+ ** [05:55:09 2009-09-16] 90399: resque: Forked 90401 at 1253141709
+ ** [05:55:09 2009-09-16] 90401: resque: Processing default since 1253141709
+ Processed a job!
+ ** [05:55:10 2009-09-16] 90401: done: (Job{default} | Demo::Job | [{}])
+
+Notice that our workers `require 'job'` in our `Rakefile`. This
+ensures they have our app loaded and can access the job classes.
+
+### Scaling the Demo Worker
+
+To add more workers:
+
+ $ vmc instances resque-worker +2
+
+### Starting the Resque frontend
+
+Great, now let's check out the Resque frontend. Either click on 'View
+Resque' in your web browser or run:
+
+ $ open http://my-resque-server.cloudfoundry.com/resque/
+
+You should see the Resque web frontend. 404 page? Don't forget the
+trailing slash!
+
+### That's it!
+
+Click around, add some more queues, add more jobs, do whatever, have fun.
View
8 Rakefile
@@ -0,0 +1,8 @@
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
+require 'resque/tasks'
+require 'job'
+
+desc "Start the demo using `rackup`"
+task :start do
+ exec "rackup config.ru"
+end
View
38 app.rb
@@ -0,0 +1,38 @@
+require 'sinatra/base'
+require 'resque'
+require 'job'
+
+module Demo
+ class App < Sinatra::Base
+ get '/' do
+ info = Resque.info
+ out = "<html><head><title>Resque Demo</title></head><body>"
+ out << "<p>"
+ out << "There are #{info[:pending]} pending and "
+ out << "#{info[:processed]} processed jobs across #{info[:queues]} queues."
+ out << "</p>"
+ out << '<form method="POST">'
+ out << '<input type="submit" value="Create New Job"/>'
+ out << '&nbsp;&nbsp;<a href="/resque/">View Resque</a>'
+ out << '</form>'
+
+ out << "<form action='/failing' method='POST''>"
+ out << '<input type="submit" value="Create Failing New Job"/>'
+ out << '&nbsp;&nbsp;<a href="/resque/">View Resque</a>'
+ out << '</form>'
+
+ out << "</body></html>"
+ out
+ end
+
+ post '/' do
+ Resque.enqueue(Job, params)
+ redirect "/"
+ end
+
+ post '/failing' do
+ Resque.enqueue(FailingJob, params)
+ redirect "/"
+ end
+ end
+end
View
19 config.ru
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+require 'logger'
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
+require 'app'
+require 'resque/server'
+
+use Rack::ShowExceptions
+
+# Set the AUTH env variable to your basic auth password to protect Resque.
+AUTH_PASSWORD = ENV['AUTH']
+if AUTH_PASSWORD
+ Resque::Server.use Rack::Auth::Basic do |username, password|
+ password == AUTH_PASSWORD
+ end
+end
+
+run Rack::URLMap.new \
+ "/" => Demo::App.new,
+ "/resque" => Resque::Server.new
View
22 job.rb
@@ -0,0 +1,22 @@
+require 'resque'
+
+module Demo
+ module Job
+ @queue = :default
+
+ def self.perform(params)
+ sleep 1
+ puts "Processed a job!"
+ end
+ end
+
+ module FailingJob
+ @queue = :failing
+
+ def self.perform(params)
+ sleep 1
+ raise 'not processable!'
+ puts "Processed a job!"
+ end
+ end
+end
View
14 server-manifest.yml
@@ -0,0 +1,14 @@
+---
+applications:
+ .:
+ framework:
+ name: rack
+ info:
+ mem: 128M
+ description: Rack Application
+ exec:
+ mem: 128M
+ instances: 1
+ services:
+ work-queue:
+ type: redis
View
17 worker-manifest.yml
@@ -0,0 +1,17 @@
+---
+applications:
+ .:
+ framework:
+ name: standalone
+ info:
+ mem: 64M
+ description: Standalone Application
+ exec:
+ runtime: ruby18
+ command: bundle exec rake VERBOSE=true QUEUE=default resque:work
+ url:
+ instances: 1
+ services:
+ work-queue:
+ type: redis
+ mem: 128M

0 comments on commit bcfd2f1

Please sign in to comment.
Something went wrong with that request. Please try again.