From a2277d7ea58cdf797edee9205add92bdaf7db4ca Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 7 May 2012 10:23:16 +0800 Subject: [PATCH] now jobs is working --- Gemfile | 4 ++-- app/jobs/fetch_time.rb | 14 ++++++++------ config/initializers/resque.rb | 23 ++++++++++++++--------- config/resque.yml | 2 -- config/resque_schedule.yml | 9 ++++----- config/routes.rb | 2 +- 6 files changed, 29 insertions(+), 25 deletions(-) delete mode 100644 config/resque.yml diff --git a/Gemfile b/Gemfile index a6b96ff2..6e6bc39c 100644 --- a/Gemfile +++ b/Gemfile @@ -19,8 +19,8 @@ gem "mongo_session_store-rails3" gem 'nokogiri' gem 'radius' gem 'rake' -gem 'resque-scheduler', :require => 'resque_scheduler' -gem 'resque', :require => "resque/server" +gem 'resque' # background jobs +gem 'resque-scheduler' # job scheduling gem 'ruby-debug19' gem 'rubyzip' gem 'sinatra' diff --git a/app/jobs/fetch_time.rb b/app/jobs/fetch_time.rb index 70e58b2b..7758cace 100644 --- a/app/jobs/fetch_time.rb +++ b/app/jobs/fetch_time.rb @@ -1,11 +1,13 @@ -require 'open-uri' -require 'nokogiri' +# require 'open-uri' +# require 'nokogiri' module FetchTime - @queue = :fetch_time + @queue = :my_job_queue def self.perform() - 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 +# 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 69eabc9c..69a535f3 100644 --- a/config/initializers/resque.rb +++ b/config/initializers/resque.rb @@ -1,15 +1,20 @@ require 'resque_scheduler' -require 'resque_scheduler/server' -require 'yaml' +# require 'resque_scheduler/server' +# require 'yaml' -rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..' -rails_env = ENV['RAILS_ENV'] || 'development' +Resque.redis = 'localhost:6379' +Resque.redis.namespace = "resque:SchedulerExample" -resque_config = YAML.load_file(rails_root + '/config/resque.yml') -Resque.redis = resque_config[rails_env] +# 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.schedule = YAML.load_file("#{Rails.root}/config/resque_schedule.yml") Dir["#{Rails.root}/app/jobs/*.rb"].each { |file| require file } -# current_path = Rails.root.to_s.gsub(/\s/,'\ ') -# queues = [:test] +# 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 diff --git a/config/resque.yml b/config/resque.yml deleted file mode 100644 index f874633c..00000000 --- a/config/resque.yml +++ /dev/null @@ -1,2 +0,0 @@ -development: localhost:6379 -production: localhost:6379 diff --git a/config/resque_schedule.yml b/config/resque_schedule.yml index 08b1b7ea..6c960ede 100644 --- a/config/resque_schedule.yml +++ b/config/resque_schedule.yml @@ -1,6 +1,5 @@ -time_to_talk_a_rest: - cron: "*/5 * * * *" +do_my_job: + every: 30s class: FetchTime - queue: daemons - rails_env: development - description: Send Email for Remind Time + args: + description: Runs the perform method in MyJob diff --git a/config/routes.rb b/config/routes.rb index 51044970..f84063da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Orbit::Application.routes.draw do - + mount Resque::Server, :at => "/admin/resque" devise_for :users # routes for sinatra app