Permalink
Browse files

Initial extraction from SubMate

  • Loading branch information...
0 parents commit 4d607b2d100f2505daa720bb09e32082b9735fb2 Clément committed Oct 18, 2010
Showing with 112 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +4 −0 Gemfile
  3. +36 −0 Gemfile.lock
  4. +23 −0 README.md
  5. +8 −0 Rakefile
  6. +16 −0 config.ru
  7. +14 −0 config_resque.rb
  8. +4 −0 jobs/sample_task.rb
  9. +5 −0 resque_schedule.yml
@@ -0,0 +1,2 @@
+.bundle
+.rvmrc
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+gem 'system_timer', '1.1.1',:git => "http://github.com/ph7/system-timer.git" # suggested by redis
+gem 'json'
+gem 'resque-scheduler'
@@ -0,0 +1,36 @@
+GIT
+ remote: http://github.com/ph7/system-timer.git
+ revision: 38f44eb8ed7ac5992fb04d86e529b27c4500ad44
+ specs:
+ system_timer (1.1.1)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ json (1.4.6)
+ rack (1.2.1)
+ redis (2.0.11)
+ redis-namespace (0.8.0)
+ redis (< 3.0.0)
+ resque (1.10.0)
+ json (~> 1.4.6)
+ redis-namespace (~> 0.8.0)
+ sinatra (>= 0.9.2)
+ vegas (~> 0.1.2)
+ resque-scheduler (1.9.6)
+ redis (>= 2.0.1)
+ resque (>= 1.8.0)
+ rufus-scheduler
+ rufus-scheduler (2.0.6)
+ sinatra (1.0)
+ rack (>= 1.0)
+ vegas (0.1.8)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ json
+ resque-scheduler
+ system_timer (= 1.1.1)!
@@ -0,0 +1,23 @@
+**RemoteScheduler** allows you to drive distant Heroku app workers, scheduling their tasks,
+using [Resque Scheduler](http://github.com/bvandenbos/resque-scheduler/) on Heroku.
+
+Works on bambo-ree-1.8.7 and bamboo-mri-1.9.2
+
+All you need is to put some classes' skeleton into jobs folder (see _jobs/sample.rb_),
+to schedule your tasks in _resque\_schedule.yml_, to deploy and define these ENV vars
+(using _[heroku config ...](http://docs.heroku.com/config-vars)_) :
+
+* RESQUEWEB_LOGIN (to connect to the resque-web utility)
+
+* RESQUEWEB_PWD
+
+* REMOTE\_REDIS\_URL (the [Redis To Go url](http://addons.heroku.com/redistogo) of your main app)
+
+Then, you're ok to run one (and only one) worker which will act as the scheduler for your
+distant main app.
+
+I extracted this from the coming soon release of **[SubMate](http://www.submate.com)** which needs very
+frequent tasks that Heroku's default cron can't handle.
+
+Don't hesitate to contact me for any question or request !
+
@@ -0,0 +1,8 @@
+require 'resque_scheduler/tasks'
+require './jobs/daily_story_updater'
+require './jobs/frequent_story_updater'
+require './jobs/relevance_updater'
+require './config_resque'
+desc "Alias for resque:work (To run workers on Heroku)"
+task "jobs:work" => "resque:scheduler"
+
@@ -0,0 +1,16 @@
+require 'resque/server'
+require 'resque_scheduler'
+require './config_resque.rb'
+Dir["./jobs/*.rb"].each { |file| require file }
+
+use Rack::Auth::Basic do |username, password|
+ [username, password] == [ENV["RESQUEWEB_LOGIN"], ENV["RESQUEWEB_PWD"]]
+end
+
+
+run Rack::URLMap.new \
+ "/" => lambda { |env|
+ [404, {'Content-Type' => 'text/html'}, ["<html><head><title>Dammit !</title></head><body>There's nothing to see here !</body></html>"]]
+ },
+ "/resque" => Resque::Server.new
+
@@ -0,0 +1,14 @@
+require 'uri'
+require 'redis'
+require 'resque'
+require 'resque_scheduler'
+require 'yaml'
+
+uri = ENV["REMOTE_REDIS_URL"]? URI.parse(ENV["REMOTE_REDIS_URL"]) : URI.parse("redis://localhost:6379")
+
+
+REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
+
+Resque.redis = REDIS
+Resque.schedule = YAML.load_file(File.join(File.dirname(__FILE__), 'resque_schedule.yml'))
+
@@ -0,0 +1,4 @@
+class SampleTask
+ @queue = :sample
+end
+
@@ -0,0 +1,5 @@
+sample:
+ cron: */5 * * * *
+ class: SampleTask
+ description: Sample task every 5 minutes
+

0 comments on commit 4d607b2

Please sign in to comment.