From f3b58ea36d148e620b7c13c01f99cef08f799fdb Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Fri, 13 Apr 2012 12:10:47 +0800 Subject: [PATCH] starting Resque --- Gemfile | 5 ++--- Gemfile.lock | 5 +++-- app/jobs/fetch_time.rb | 14 +++++--------- config/initializers/resque.rb | 24 +++++++++--------------- config/resque.yml | 2 ++ config/resque_schedule.yml | 21 +++++---------------- 6 files changed, 26 insertions(+), 45 deletions(-) create mode 100644 config/resque.yml diff --git a/Gemfile b/Gemfile index d6129092..a6b96ff2 100644 --- a/Gemfile +++ b/Gemfile @@ -19,9 +19,8 @@ gem "mongo_session_store-rails3" gem 'nokogiri' gem 'radius' gem 'rake' -gem 'resque' # background jobs -gem 'resque-scheduler' # job scheduling -gem 'resque-restriction' +gem 'resque-scheduler', :require => 'resque_scheduler' +gem 'resque', :require => "resque/server" gem 'ruby-debug19' gem 'rubyzip' gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock index 16acce21..8e94537e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -161,8 +161,6 @@ GEM redis-namespace (~> 1.0.2) sinatra (>= 0.9.2) vegas (~> 0.1.2) - resque-restriction (0.3.0) - resque (>= 1.7.0) resque-scheduler (1.9.9) redis (>= 2.0.1) resque (>= 1.8.0) @@ -278,7 +276,10 @@ DEPENDENCIES rails (>= 3.1.0, < 3.2.0) rake resque +<<<<<<< HEAD resque-restriction +======= +>>>>>>> starting Resque resque-scheduler rspec (~> 2.0) rspec-rails (~> 2.0) diff --git a/app/jobs/fetch_time.rb b/app/jobs/fetch_time.rb index 5fce3036..70e58b2b 100644 --- a/app/jobs/fetch_time.rb +++ b/app/jobs/fetch_time.rb @@ -1,15 +1,11 @@ -# require 'open-uri' -# require 'nokogiri' -class FetchTime < Resque::Plugins::RestrictionJob - restrict :per_300 => 10 - - @queue = :low +require 'open-uri' +require 'nokogiri' +module FetchTime + @queue = :fetch_time def self.perform() -# sleep 10 + sleep 10 doc = Nokogiri::HTML(open('http://www.timeanddate.com/worldclock/city.html?n=241')) CronMail.time_check(doc.at('#ct').children.first.text).deliver - puts "Mail Sent" - true end end diff --git a/config/initializers/resque.rb b/config/initializers/resque.rb index f6f08406..5bfe6d56 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -1,20 +1,14 @@ -require 'resque_scheduler' -# require 'resque_scheduler/server' -# require 'yaml' +require 'resque_scheduler'require 'resque_scheduler/server' +require 'yaml' -Resque.redis = 'localhost:6379' -#Resque.redis.namespace = "resque:SchedulerExample" +rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..' +rails_env = ENV['RAILS_ENV'] || 'development' -# If you want to be able to dynamically change the schedule, -# uncomment this line. A dynamic schedule can be updated via the -# Resque::Scheduler.set_schedule (and remove_schedule) methods. -# When dynamic is set to true, the scheduler process looks for -# schedule changes and applies them on the fly. -# Note: This feature is only available in >=2.0.0. -#Resque::Scheduler.dynamic = true +resque_config = YAML.load_file(rails_root + '/config/resque.yml') +Resque.redis = resque_config[rails_env] +Resque.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml") Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file } -# The schedule doesn't need to be stored in a YAML, it just needs to -# be a hash. YAML is usually the easiest. -Resque.schedule = YAML.load_file(Rails.root.join('config', 'resque_schedule.yml')) \ No newline at end of file +# current_path = Rails.root.to_s.gsub(/\s/,'\ ') +# queues = [:test] diff --git a/config/resque.yml b/config/resque.yml new file mode 100644 index 00000000..f874633c --- /dev/null +++ b/config/resque.yml @@ -0,0 +1,2 @@ +development: localhost:6379 +production: localhost:6379 diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 10f97f5f..08b1b7ea 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -1,17 +1,6 @@ -do_mail_matt: - every: 10s +time_to_talk_a_rest: + cron: "*/5 * * * *" class: FetchTime - args: - description: Runs the perform method in FetchTime - -nccu_daily_ldap_sync: - cron: 30 * * * * * - class: SyncDb - args: - description: Runs the perform method in SnycDB - -nccu_claender_sync: - every: 1m - class: NccuCalendar - args: - description: Runs the perform method in NccuCalendar \ No newline at end of file + queue: daemons + rails_env: development + description: Send Email for Remind Time