Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switching to resque-scheduler for regular jobs

  • Loading branch information...
commit b9469215b068c27cece145c46074a9cee1b8a28d 1 parent 07f93d1
@chewbranca chewbranca authored
Showing with 1,617 additions and 2,550 deletions.
  1. +1 −0  .gitignore
  2. +2 −0  Rakefile
  3. +0 −4 app/models/user.rb
  4. +12 −0 app/workers/feeds_worker.rb
  5. +8 −0 app/workers/test_worker.rb
  6. +54 −0 config/application.god.sample
  7. +2 −7 config/deploy.rb
  8. +2 −1  config/environment.rb
  9. +2 −1  config/initializers/002_load_libs.rb
  10. +4 −0 config/initializers/resque.rb
  11. +7 −0 config/resque_schedule.yml
  12. +0 −24 config/schedule.rb
  13. +58 −71 lib/feed_parser.rb
  14. +3 −160 lib/tasks/feeds.rake
  15. +12 −0 lib/tasks/queue.rake
  16. +17 −0 lib/tasks/resque.rake
  17. +0 −3  vendor/gems/whenever-0.4.1/.gitignore
  18. +0 −109 vendor/gems/whenever-0.4.1/.specification
  19. +0 −82 vendor/gems/whenever-0.4.1/CHANGELOG.rdoc
  20. +0 −115 vendor/gems/whenever-0.4.1/README.rdoc
  21. +0 −32 vendor/gems/whenever-0.4.1/Rakefile
  22. +0 −30 vendor/gems/whenever-0.4.1/bin/whenever
  23. +0 −69 vendor/gems/whenever-0.4.1/bin/wheneverize
  24. +0 −31 vendor/gems/whenever-0.4.1/lib/whenever.rb
  25. +0 −15 vendor/gems/whenever-0.4.1/lib/whenever/base.rb
  26. +0 −108 vendor/gems/whenever-0.4.1/lib/whenever/command_line.rb
  27. +0 −161 vendor/gems/whenever-0.4.1/lib/whenever/job_list.rb
  28. +0 −27 vendor/gems/whenever-0.4.1/lib/whenever/job_types/default.rb
  29. +0 −12 vendor/gems/whenever-0.4.1/lib/whenever/job_types/rake_task.rb
  30. +0 −12 vendor/gems/whenever-0.4.1/lib/whenever/job_types/runner.rb
  31. +0 −139 vendor/gems/whenever-0.4.1/lib/whenever/outputs/cron.rb
  32. +0 −54 vendor/gems/whenever-0.4.1/lib/whenever/outputs/cron/output_redirection.rb
  33. +0 −3  vendor/gems/whenever-0.4.1/lib/whenever/version.rb
  34. +0 −101 vendor/gems/whenever-0.4.1/test/command_line_test.rb
  35. +0 −226 vendor/gems/whenever-0.4.1/test/cron_test.rb
  36. +0 −178 vendor/gems/whenever-0.4.1/test/output_at_test.rb
  37. +0 −37 vendor/gems/whenever-0.4.1/test/output_command_test.rb
  38. +0 −56 vendor/gems/whenever-0.4.1/test/output_env_test.rb
  39. +0 −74 vendor/gems/whenever-0.4.1/test/output_rake_test.rb
  40. +0 −289 vendor/gems/whenever-0.4.1/test/output_redirection_test.rb
  41. +0 −209 vendor/gems/whenever-0.4.1/test/output_runner_test.rb
  42. +0 −33 vendor/gems/whenever-0.4.1/test/test_helper.rb
  43. +0 −77 vendor/gems/whenever-0.4.1/whenever.gemspec
  44. +63 −0 vendor/plugins/resque-scheduler/HISTORY.md
  45. +21 −0 vendor/plugins/resque-scheduler/LICENSE
  46. +215 −0 vendor/plugins/resque-scheduler/README.markdown
  47. +56 −0 vendor/plugins/resque-scheduler/Rakefile
  48. +155 −0 vendor/plugins/resque-scheduler/lib/resque/scheduler.rb
  49. +156 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler.rb
  50. +57 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler/server.rb
  51. +42 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler/server/views/delayed.erb
  52. +26 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler/server/views/delayed_timestamp.erb
  53. +35 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler/server/views/scheduler.erb
  54. +24 −0 vendor/plugins/resque-scheduler/lib/resque_scheduler/tasks.rb
  55. +3 −0  vendor/plugins/resque-scheduler/lib/resque_scheduler/version.rb
  56. +83 −0 vendor/plugins/resque-scheduler/resque-scheduler.gemspec
  57. +2 −0  vendor/plugins/resque-scheduler/tasks/resque_scheduler.rake
  58. +199 −0 vendor/plugins/resque-scheduler/test/delayed_queue_test.rb
  59. +115 −0 vendor/plugins/resque-scheduler/test/redis-test.conf
  60. +31 −0 vendor/plugins/resque-scheduler/test/resque-web_test.rb
  61. +72 −0 vendor/plugins/resque-scheduler/test/scheduler_test.rb
  62. +78 −0 vendor/plugins/resque-scheduler/test/test_helper.rb
View
1  .gitignore
@@ -21,6 +21,7 @@ config/application.god
config/compass.config
config/compass.rb
!config/widgets.yml
+!config/resque_schedule.yml
!config/cucumber.yml
config/deploy/*.rb
!config/deploy/sample.rb
View
2  Rakefile
@@ -9,6 +9,8 @@ require 'rake/rdoctask'
require 'tasks/rails'
+require 'resque_scheduler/tasks'
+
begin
require 'sitemap_generator/tasks'
rescue Exception => e
View
4 app/models/user.rb
@@ -188,10 +188,6 @@ def facebook_user?
return !fb_user_id.nil? && fb_user_id > 0
end
- def accepts_email_notifications
- self.email.present? and self.user_profile.receive_email_notifications == true
- end
-
def friends
[]
end
View
12 app/workers/feeds_worker.rb
@@ -0,0 +1,12 @@
+class FeedsWorker
+ @queue = :feeds
+
+ def self.perform(feed_id = nil)
+ if feed_id
+ N2::FeedParser.update_feed Feed.find(feed_id)
+ else
+ N2::FeedParser.update_feeds
+ end
+ end
+
+end
View
8 app/workers/test_worker.rb
@@ -0,0 +1,8 @@
+class TestWorker
+ @queue = :test
+
+ def self.perform(foo, bar)
+ Rails.logger.debug("****RAN TEST WORKER****")
+ #Rails.logger.debug.flush
+ end
+end
View
54 config/application.god.sample
@@ -178,3 +178,57 @@ num_workers.times do |num|
end
end
end
+
+ God.watch do |w|
+ w.name = "resque-scheduler-#{application}"
+ w.group = 'resque-scheduler'
+ w.interval = 30.seconds
+ w.env = {"INITIALIZER_PATH"=>"#{rails_root}/config/initializers/resque.rb", "RAILS_ENV"=>rails_env}
+ w.start = "/usr/bin/rake -f #{rails_root}/Rakefile resque:scheduler"
+ #w.start = "/usr/bin/rake -f #{rails_root}/Rakefile environment resque:work& &> log/resque_worker_#{num}.log && echo $! > tmp/pids/resque_worker_#{num}.pid && echo 0"
+ #w.start = "/usr/bin/rake -f #{rails_root}/Rakefile environment resque:work &> log/resque_worker_#{num}.log && echo !$ > tmp/pids/resque_worker_#{num}.pid"
+ #w.start = "cd #{rails_root} && RAILS_ENV=#{rails_env} INTERVAL=1 QUEUES=* rake resque:work &> log/resque_worker_#{num}.log & echo $! > tmp/pids/resque_worker_#{num}.pid"
+ #w.pid_file = "#{rails_root}/tmp/pids/resque_worker_#{num}.pid"
+
+ #w.behavior(:clean_pid_file)
+
+ w.uid = 'deploy'
+ w.gid = 'deploy'
+
+ # retart if memory gets too high
+ w.transition(:up, :restart) do |on|
+ on.condition(:memory_usage) do |c|
+ c.above = 250.megabytes
+ c.times = 2
+ end
+ end
+
+ # determine the state on startup
+ w.transition(:init, { true => :up, false => :start }) do |on|
+ on.condition(:process_running) do |c|
+ c.running = true
+ end
+ end
+
+ # determine when process has finished starting
+ w.transition([:start, :restart], :up) do |on|
+ on.condition(:process_running) do |c|
+ c.running = true
+ c.interval = 5.seconds
+ end
+
+ # failsafe
+ on.condition(:tries) do |c|
+ c.times = 5
+ c.transition = :start
+ c.interval = 5.seconds
+ end
+ end
+
+ # start if process is not running
+ w.transition(:up, :start) do |on|
+ on.condition(:process_running) do |c|
+ c.running = false
+ end
+ end
+ end
View
9 config/deploy.rb
@@ -28,8 +28,6 @@
deploy.cleanup
end
-after "deploy:symlink", "deploy:update_crontab"
-
before("deploy") do
deploy.god.stop
end
@@ -44,12 +42,14 @@
after("deploy") do
run "cd #{current_path} && rake n2:queue:restart_workers"
+ run "APP_NAME=#{application} cd #{current_path} && rake n2:queue:restart_scheduler"
deploy.god.start
newrelic.notice_deployment
end
after("deploy:migrations") do
run "cd #{current_path} && rake n2:queue:restart_workers"
+ run "APP_NAME=#{application} cd #{current_path} && rake n2:queue:restart_scheduler"
deploy.god.start
newrelic.notice_deployment
end
@@ -120,11 +120,6 @@
run "cat #{current_path}/tmp/pids/unicorn.pid | xargs kill -QUIT"
end
- desc "Update the crontab file"
- task :update_crontab, :roles => :db do
- run "cd #{release_path} && whenever --set 'environment=#{rails_env}&cron_log=#{shared_path}/log/cron.log' --update-crontab #{application}"
- end
-
desc "Bootstrap initial app and setup database"
task :cold_bootstrap do
update
View
3  config/environment.rb
@@ -36,7 +36,6 @@
# config.gem "aws-s3", :lib => "aws/s3"
#config.gem "haml"
config.gem "eycap"
- config.gem "whenever"
config.gem "rack"
config.gem "formtastic"
config.gem "hpricot"
@@ -49,6 +48,8 @@
config.gem "oauth"
config.gem "twitter"
config.gem "bitly"
+ config.gem "resque"
+ config.gem "resque-scheduler", :lib => 'resque_scheduler'
config.gem 'sitemap_generator', :lib => false
# Only load the plugins named here, in the order given (default is alphabetical).
View
3  config/initializers/002_load_libs.rb
@@ -36,4 +36,5 @@
require "#{RAILS_ROOT}/lib/zvent_gem_addon.rb"
-require "#{RAILS_ROOT}/lib/string_extensions.rb"
+require "#{RAILS_ROOT}/lib/string_extensions.rb"
+require "#{RAILS_ROOT}/lib/feed_parser.rb"
View
4 config/initializers/resque.rb
@@ -1,4 +1,5 @@
require 'yaml'
+require 'resque'
rails_root = ENV['RAILS_ROOT'] || File.expand_path(File.dirname(__FILE__) + '/../..')
rails_env = ENV['RAILS_ENV'] || 'development'
@@ -9,6 +10,9 @@
app_name = rails_root =~ %r(/([^/]+)/(current|release)) ? $1 : nil
Resque.redis.namespace = "resque:#{app_name}" if app_name
+require 'resque_scheduler'
+Resque.schedule = YAML.load_file(File.join(rails_root, 'config/resque_schedule.yml'))
+
begin
NotificationWorker.class
PFEED_RESQUE_KLASS = NotificationWorker
View
7 config/resque_schedule.yml
@@ -0,0 +1,7 @@
+parse_feeds:
+ cron: "30 * * * *"
+ class: FeedsWorker
+ queue: feeds
+ args:
+ rails_env: development, staging, production
+ description: "This job will parse the RSS/atom feeds"
View
24 config/schedule.rb
@@ -1,24 +0,0 @@
-# Use this file to easily define all of your cron jobs.
-#
-# It's helpful, but not entirely necessary to understand cron before proceeding.
-# http://en.wikipedia.org/wiki/Cron
-
-# Example:
-#
-# set :output, "/path/to/my/cron_log.log"
-#
-# every 2.hours do
-# command "/usr/bin/some_great_command"
-# runner "MyModel.some_method"
-# rake "some:great:rake:task"
-# end
-#
-# every 4.days do
-# runner "AnotherModel.prune_old_records"
-# end
-
-# Learn more: http://github.com/javan/whenever
-
-every 30.minutes do
- rake "n2:feeds:parse:all"
-end
View
129 lib/feed_parser.rb
@@ -1,85 +1,72 @@
-require 'rss'
+require 'feedzirra'
-class FeedParser
- class << self; attr_accessor :title_fields, :date_fields, :body_fields, :link_fields, :image_fields; end
- @title_fields = ['title', 'subtitle', 'link']
- @date_fields = ['updated', 'date', 'updated_at', 'pubDate', 'published', 'lastBuildDate', 'dc_date']
- @body_fields = ['description', 'content', 'summary', 'caption']
- @link_fields = ['link', 'guid']
- @image_fields = ['image', 'imageUrl', 'image_url', 'logo', 'icon']
+module N2
+ class FeedParser
+ def self.update_feeds
+ feeds = Feed.find(:all, :conditions => ["specialType = ?", "default"])
+ feeds.each { |feed| update_feed feed, false }
- ['title', 'date', 'body', 'link', 'image'].each do |func|
- define_method func do |*args|
- feed, fields, is_atom = *args
- feed ||= @feed
- fields ||= FeedParser.send("#{func}_fields")
- atom_feed ||= self.atom_feed?
-
- get_value feed, fields, atom_feed
- end
- end
-
- def initialize(url)
- @url = url
- @feed_type = false
- @title_filters = Metadata::TitleFilter.all.map(&:keyword)
- parse
- end
-
- def parse
- @raw_feed = RSS::Parser.parse(@url)
- raise FeedError, "Invalid feed url: #{@url}" if @raw_feed.nil?
- if @raw_feed.respond_to? 'channel'
- @feed_type = 'RSS'
- @feed = @raw_feed.channel
- else
- @feed_type = 'Atom'
- @feed = @raw_feed
+ expire_newswire_cache
end
- end
- def get_value feed_object, fields, is_atom
- command = fields.select { |field| feed_object.respond_to? field }.first
- return nil unless command.present?
+ def self.update_feed(feed, trigger_expire_cache = true)
+ return false unless feed
+ Rails.logger.info "Running feedzirra on #{feed.item_title}"
+ begin
+ rss = Feedzirra::Feed.fetch_and_parse(feed.rss)
+ rescue => e
+ Rails.logger.info "Failed to open feed at #{feed.url} -- #{e}"
+ return false
+ end
+ Rails.logger.info "The feed #{feed.title}(#{feed.url}) could not be reached -- status: #{rss.inspect}" and return false unless rss and rss.respond_to?(:entries)
+ items = rss.entries
+ Rails.logger.info "The feed #{feed.title}(#{feed.url}) is presently empty." and return false unless items.present?
+ Rails.logger.info "Parsing #{feed.title} with #{items.size} items -- updated on #{rss.last_modified} -- last fetched #{feed.last_fetched_at}"
- # If atom feed, we need to call content on the field to get the data
- original_command = command
- command = is_atom == true ? (command == 'link' ? [command, 'href'] : [command, 'content']) : command
+ feed_date = feed.last_fetched_at
+ pub_date = rss.last_modified
+ if !feed_date or (pub_date and feed_date < pub_date)
+ items.each do |item|
+ Rails.logger.info "\tChecking feed items"
+ break if feed_date and item.published and (item.published <= feed_date)
+ next if Newswire.find_by_title item.title
+ next unless item.summary and item.url and item.title
- begin
- command.inject(feed_object) { |item, cmd| item.send(cmd) }
- rescue NoMethodError
- subfields = fields.delete(original_command)
- return get_value(feed_object, subfields, is_atom) if subfields and subfields.present?
- nil
- end
- end
+ Rails.logger.info "\tCreating newswire for \"#{item.title.chomp}\""
- def atom_feed?
- @feed_type == 'Atom'
- end
+ newswire = Newswire.create!({
+ :title => item.title,
+ :caption => item.summary,
+ :created_at => item.published,
+ :url => item.url,
+ #:imageUrl => item.image,
+ :feed => feed
+ })
+ if feed.load_all?
+ Rails.logger.info "\t\tRunning quick post.."
+ if newswire.imageUrl.present? and not newswire.imageUrl =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?(jpg|jpeg|gif|png)(\?.*)?$/ix
+ Rails.logger.info "\t\t\tProcessing non standard image: #{newswire.imageUrl}"
+ unless newswire.quick_post(nil, true)
+ Rails.logger.info "\t\t\tCould not process image, skipping image."
+ newswire.update_attribute(:imageUrl, nil)
+ newswire.quick_post
+ end
+ else
+ newswire.quick_post
+ end
+ end
+ end
- def rss_feed?
- @feed_type == 'RSS'
- end
+ feed.update_attributes({:updated_at => Time.now, :last_fetched_at => (pub_date || Time.now)})
+ end
- def items
- items = []
- @raw_feed.items.each do |item|
- tempTitle = title(item)
- tempTitle = @title_filters.inject(tempTitle) {|str,key| str.gsub(%r{#{key}}, '') }
- tempTitle.sub(/^[|\s]+/,'').sub(/[|\s]+$/,'')
- items << {
- :title => tempTitle,
- :body => body(item),
- :date => date(item),
- :link => link(item),
- :image => image(item),
- }
+ expire_newswire_cache if trigger_expire_cache
end
- items
+ def self.expire_newswire_cache
+ Rails.logger.info "Expiring newswires cache"
+ NewswireSweeper.expire_newswires
+ end
end
-
end
View
163 lib/tasks/feeds.rake
@@ -1,178 +1,21 @@
require 'feed_parser'
-require 'magic_parse'
-require 'feedzirra'
namespace :n2 do
namespace :feeds do
namespace :parse do
desc "Parse All Feeds"
task :all => :environment do
- feeds = Feed.find(:all, :conditions => ["specialType = ?", "default"])
-
- feeds.each { |f| update_feed f }
-
- NewswireSweeper.expire_newswires
+ N2::FeedParser.update_feeds
end
desc "Parse One Feed from 'feed_id'"
task :one => :environment do
raise "This task expects feed_id to be provied with an integer" unless ENV.include?("feed_id")
feed = Feed.find_by_id ENV["feed_id"]
- raise "Invalid feed id." unless feed.present?
-
- update_feed feed
-
- NewswireSweeper.expire_newswires
- end
- end
- end
-end
-
-def update_feed(feed)
- return new_update_feed(feed) if (feed.load_all? and feed.loadOptions == 'full_html') or feed.loadOptions == 'magic_parse'
- return feedzirra_update_feed(feed)
- begin
- #rss = RSS::Parser.parse(open(feed.rss).read, false)
- rss = FeedParser.new(feed.rss)
- rescue => e
- puts "Failed to open feed at #{feed.url} -- #{e}"
- return false
- end
-
- puts "The feed #{feed.title}(#{feed.url}) is presently invalid." or return false unless rss.present?
- puts "The feed #{feed.title}(#{feed.url}) is presently empty." or return false unless rss.items.present?
-
- puts "Parsing #{feed.title} with #{rss.items.size} items -- updated on #{rss.date} -- last fetched #{feed.last_fetched_at}"
-
- feed_date = feed.last_fetched_at
- added_item = false
- if !feed_date or (rss.date and feed_date < rss.date)
- rss.items.each do |item|
- break if feed_date and item[:date] <= feed_date
- next if Newswire.find_by_title item[:title]
- next unless item[:body] and item[:link] and item[:title] and item[:date]
-
- puts "\tCreating newswire for \"#{item[:title].chomp}\""
+ raise "Invalid feed id." unless feed
- newswire = Newswire.create!({
- :title => item[:title],
- :caption => item[:body],
- :created_at => item[:date].to_s,
- :url => item[:link],
- :imageUrl => item[:image],
- :feed => feed
- })
-
- added_item = true
-
- if feed.load_all?
- puts "\t\tRunning quick post"
- newswire.quick_post
+ N2::FeedParser.update_feed feed
end
-
end
- if added_item
- WidgetSweeper.expire_item "newest_newswires"
- end
- feed.update_attributes({:updated_at => Time.now, :last_fetched_at => rss.date.to_s})
- end
-end
-
-def new_update_feed(feed)
- puts "Running full parse on #{feed.title}"
- begin
- rss = MagicParse.new(feed.rss)
- rescue => e
- puts "Failed to open feed at #{feed.url} -- #{e}"
- return false
- end
- items = rss.get_items
- puts "The feed #{feed.title}(#{feed.url}) is presently empty." or return false unless items.present?
- puts "Parsing #{feed.title} with #{items.size} items -- updated on #{rss.get_pub_date} -- last fetched #{feed.last_fetched_at}"
-
- feed_date = feed.last_fetched_at
- pub_date = Time.parse(rss.get_pub_date)
- if !feed_date or (pub_date and feed_date < pub_date)
- items.each do |item|
- break if feed_date and Time.parse(item[:date]) <= feed_date
- next if Newswire.find_by_title item[:title]
- next unless item[:body] and item[:link] and item[:title] and item[:date]
-
- puts "\tCreating newswire for \"#{item[:title].chomp}\""
-
- newswire = Newswire.create!({
- :title => item[:title],
- :caption => item[:body],
- :created_at => item[:date].to_s,
- :url => item[:link],
- :imageUrl => item[:image],
- :feed => feed
- })
- if feed.load_all?
- puts "\t\tRunning quick post.."
- if newswire.imageUrl.present? and not newswire.imageUrl =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?(jpg|jpeg|gif|png)(\?.*)?$/ix
- puts "\t\t\tProcessing non standard image: #{newswire.imageUrl}"
- unless newswire.quick_post(nil, true)
- puts "\t\t\tCould not process image, skipping image."
- newswire.update_attribute(:imageUrl, nil)
- newswire.quick_post
- end
- else
- newswire.quick_post
- end
- end
- end
-
- feed.update_attributes({:updated_at => Time.now, :last_fetched_at => (pub_date.to_s || Time.now)})
- end
-end
-
-def feedzirra_update_feed(feed)
- puts "Running feedzirra on #{feed.title}"
- begin
- rss = Feedzirra::Feed.fetch_and_parse(feed.rss)
- rescue => e
- puts "Failed to open feed at #{feed.url} -- #{e}"
- return false
- end
- puts "The feed #{feed.title}(#{feed.url}) could not be reached -- status: #{rss.inspect}" or return false unless rss and rss.respond_to?(:entries)
- items = rss.entries
- puts "The feed #{feed.title}(#{feed.url}) is presently empty." or return false unless items.present?
- puts "Parsing #{feed.title} with #{items.size} items -- updated on #{rss.last_modified} -- last fetched #{feed.last_fetched_at}"
-
- feed_date = feed.last_fetched_at
- pub_date = rss.last_modified
- if !feed_date or (pub_date and feed_date < pub_date)
- items.each do |item|
- break if feed_date and item.published and (item.published <= feed_date)
- next if Newswire.find_by_title item.title
- next unless item.summary and item.url and item.title
-
- puts "\tCreating newswire for \"#{item.title.chomp}\""
-
- newswire = Newswire.create!({
- :title => item.title,
- :caption => item.summary,
- :created_at => item.published,
- :url => item.url,
- #:imageUrl => item.image,
- :feed => feed
- })
- if false and feed.load_all?
- puts "\t\tRunning quick post.."
- if newswire.imageUrl.present? and not newswire.imageUrl =~ /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?(jpg|jpeg|gif|png)(\?.*)?$/ix
- puts "\t\t\tProcessing non standard image: #{newswire.imageUrl}"
- unless newswire.quick_post(nil, true)
- puts "\t\t\tCould not process image, skipping image."
- newswire.update_attribute(:imageUrl, nil)
- newswire.quick_post
- end
- else
- newswire.quick_post
- end
- end
- end
-
- feed.update_attributes({:updated_at => Time.now, :last_fetched_at => (pub_date || Time.now)})
end
end
View
12 lib/tasks/queue.rake
@@ -11,6 +11,18 @@ namespace :n2 do
puts "Stopping Resque workers with pids: #{pids.inspect}"
system("kill -QUIT #{pids.join ' '}") if pids.any?
end
+
+ desc "Restart Resque scheduler"
+ task :restart_scheduler => [:stop_scheduler] do
+ # Stop scheduler and let god restart them
+ end
+
+ desc "Stop Resque Scheduler"
+ task :stop_scheduler do
+ raise "You must specify the ENV variable APP_NAME" unless ENV['APP_NAME'].present?
+ puts "Stopping Resque Scheduler"
+ system("ps aux | grep 'resque:scheduler' | grep #{ENV['APP_NAME']} | grep -v grep | awk '{ print $2 }' | xargs -r kill")
+ end
end
end
View
17 lib/tasks/resque.rake
@@ -1 +1,18 @@
task "resque:setup" => :environment
+
+#remove_task "resque:scheduler_setup"
+task "resque:scheduler_setup" do
+ puts "In custom setup with path #{ENV['load_path']}"
+ path = ENV['load_path']
+ load path.to_s.strip if path
+end
+
+=begin
+namespace :resque do
+ task :zzscheduler_setup do
+ puts "In custom setup with path #{ENV['load_path']}"
+ path = ENV['load_path']
+ load path.to_s.strip if path
+ end
+end
+=end
View
3  vendor/gems/whenever-0.4.1/.gitignore
@@ -1,3 +0,0 @@
-.DS_Store
-pkg
-doc
View
109 vendor/gems/whenever-0.4.1/.specification
@@ -1,109 +0,0 @@
---- !ruby/object:Gem::Specification
-name: whenever
-version: !ruby/object:Gem::Version
- prerelease: false
- segments:
- - 0
- - 4
- - 1
- version: 0.4.1
-platform: ruby
-authors:
-- Javan Makhmali
-autorequire:
-bindir: bin
-cert_chain: []
-
-date: 2009-11-29 00:00:00 -08:00
-default_executable:
-dependencies:
-- !ruby/object:Gem::Dependency
- name: chronic
- prerelease: false
- requirement: &id001 !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- segments:
- - 0
- - 2
- - 3
- version: 0.2.3
- type: :runtime
- version_requirements: *id001
-description: Clean ruby syntax for defining and deploying messy cron jobs.
-email: javan@javan.us
-executables:
-- whenever
-- wheneverize
-extensions: []
-
-extra_rdoc_files:
-- README.rdoc
-files:
-- .gitignore
-- CHANGELOG.rdoc
-- README.rdoc
-- Rakefile
-- bin/whenever
-- bin/wheneverize
-- lib/whenever.rb
-- lib/whenever/base.rb
-- lib/whenever/command_line.rb
-- lib/whenever/job_list.rb
-- lib/whenever/job_types/default.rb
-- lib/whenever/job_types/rake_task.rb
-- lib/whenever/job_types/runner.rb
-- lib/whenever/outputs/cron.rb
-- lib/whenever/outputs/cron/output_redirection.rb
-- lib/whenever/version.rb
-- test/command_line_test.rb
-- test/cron_test.rb
-- test/output_at_test.rb
-- test/output_command_test.rb
-- test/output_env_test.rb
-- test/output_rake_test.rb
-- test/output_redirection_test.rb
-- test/output_runner_test.rb
-- test/test_helper.rb
-- whenever.gemspec
-has_rdoc: true
-homepage: http://github.com/javan/whenever
-licenses: []
-
-post_install_message:
-rdoc_options:
-- --charset=UTF-8
-require_paths:
-- lib
-required_ruby_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- segments:
- - 0
- version: "0"
-required_rubygems_version: !ruby/object:Gem::Requirement
- requirements:
- - - ">="
- - !ruby/object:Gem::Version
- segments:
- - 0
- version: "0"
-requirements: []
-
-rubyforge_project:
-rubygems_version: 1.3.6
-signing_key:
-specification_version: 3
-summary: Clean ruby syntax for defining and deploying messy cron jobs.
-test_files:
-- test/command_line_test.rb
-- test/cron_test.rb
-- test/output_at_test.rb
-- test/output_command_test.rb
-- test/output_env_test.rb
-- test/output_rake_test.rb
-- test/output_redirection_test.rb
-- test/output_runner_test.rb
-- test/test_helper.rb
View
82 vendor/gems/whenever-0.4.1/CHANGELOG.rdoc
@@ -1,82 +0,0 @@
-== 0.4.1 / November 30th, 2009
-
-* exit(0) instead of just exit to make JRuby happy. [Elan Meng]
-
-* Fixed activesupport deprecation warning by requiring active_support. #37 [Andrew Nesbitt]
-
-
-== 0.4.0 / October 20th, 2009
-
-* New output option replaces the old cron_log option for output redirection and is much more flexible. #31 [Peer Allan]
-
-* Reorganized the lib files (http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices) and switched to Jeweler from Echoe.
-
-
-== 0.3.7 / September 4th, 2009
-
-* No longer tries (and fails) to combine @shortcut jobs. #20 [Javan Makhmali]
-
-
-== 0.3.6 / June 15th, 2009
-
-* Setting a PATH in the crontab automatically based on the user's PATH. [Javan Makhmali]
-
-
-== 0.3.5 / June 13th, 2009
-
-* Added ability to accept lists of every's and at's and intelligently group them. (ex: every 'monday, wednesday', :at => ['3pm', '6am']). [Sam Ruby]
-
-* Fixed issue with new lines. #18 [Javan Makhmali]
-
-== 0.3.1 / June 25th, 2009
-
-* Removed activesupport gem dependency. #1 [Javan Makhmali]
-
-* Switched to numeric days of the week for Solaris support (and probably others). #8 [Roger Ertesvåg]
-
-
-== 0.3.0 / June 2nd, 2009
-
-* Added ability to set variables on the fly from the command line (ex: whenever --set environment=staging). [Javan Makhmali]
-
-
-== 0.2.2 / April 30th, 2009
-
-* Days of week jobs can now accept an :at directive (ex: every :monday, :at => '5pm'). [David Eisinger]
-
-* Fixed command line test so it runs without a config/schedule.rb present. [Javan Makhmali]
-
-* Raising an exception if someone tries to specify an :at with a cron shortcut (:day, :reboot, etc) so there are no false hopes. [Javan Makhmali]
-
-
-== 0.1.7 / March 5th, 2009
-
-* Added ability to update the crontab file non-destuctively instead of only overwriting it. [Javan Makhmali -- Inspired by code submitted individually from: Tien Dung (tiendung), Tom Lea (cwninja), Kyle Maxwell (fizx), and Andrew Timberlake (andrewtimberlake) on github]
-
-
-== 0.1.5 / February 19th, 2009
-
-* Fixed load path so Whenever's files don't conflict with anything in Rails. Thanks Ryan Koopmans. [Javan Makhmali]
-
-
-== 0.1.4 / February 17th, 2009
-
-* Added --load-file and --user opts to whenever binary. [Javan Makhmali]
-
-
-== 0.1.3 / February 16th, 2009
-
-* Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
-
-* Renamed :cron_environment and :cron_path to :enviroment and :path for better (word) compatibility with rake tasks. [Javan Makhmali]
-
-* Improved test load paths so tests can be run individually. [Javan Makhmali]
-
-* Got rid of already initialized constant warning. [Javan Makhmali]
-
-* Requiring specific gem versions: Chronic >=0.2.3 and activesupport >= 1.3.0 [Javan Makhmali]
-
-
-== 0.1.0 / February 15th, 2009
-
-* Initial release [Javan Makhmali]
View
115 vendor/gems/whenever-0.4.1/README.rdoc
@@ -1,115 +0,0 @@
-== Introduction
-
-Whenever is a Ruby gem that provides a clear syntax for defining cron jobs. It outputs valid cron syntax and can even write your crontab file for you. It is designed to work well with Rails applications and can be deployed with Capistrano. Whenever works fine independently as well.
-
-Ryan Bates created a great Railscast about Whenever: http://railscasts.com/episodes/164-cron-in-ruby
-
-Discussion: http://groups.google.com/group/whenever-gem
-
-== Installation
-
-If you haven't already, get set up with http://gemcutter.org
-
- $ sudo gem install whenever
-
-In a Rails (2.1 or greater) application:
-
-in your "config/environment.rb" file:
-
- Rails::Initializer.run do |config|
- config.gem 'whenever', :lib => false, :source => 'http://gemcutter.org/'
- end
-
-== Getting started
-
- $ cd /my/rails/app
- $ wheneverize .
-
-This will create an initial "config/schedule.rb" file you.
-
-== Example schedule.rb file
-
- every 3.hours do
- runner "MyModel.some_process"
- rake "my:rake:task"
- command "/usr/bin/my_great_command"
- end
-
- every 1.day, :at => '4:30 am' do
- runner "MyModel.task_to_run_at_four_thirty_in_the_morning"
- end
-
- every :hour do # Many shortcuts available: :hour, :day, :month, :year, :reboot
- runner "SomeModel.ladeeda"
- end
-
- every :sunday, :at => '12pm' do # Use any day of the week or :weekend, :weekday
- runner "Task.do_something_great"
- end
-
-More examples on the wiki: http://wiki.github.com/javan/whenever/instructions-and-examples
-
-== Cron output
-
- $ cd /my/rails/app
- $ whenever
-
-And you'll see your schedule.rb converted to cron sytax. Note: running `whenever' with no options does not display your current crontab file, it simply shows you the output of converting your schedule.rb file.
-
-== Capistrano integration
-
-In your "config/deploy.rb" file do something like:
-
- after "deploy:symlink", "deploy:update_crontab"
-
- namespace :deploy do
- desc "Update the crontab file"
- task :update_crontab, :roles => :db do
- run "cd #{release_path} && whenever --update-crontab #{application}"
- end
- end
-
-This will update your crontab file, leaving any existing entries unharmed. When using the <code>--update-crontab</code> option, Whenever will only update the entries in your crontab file related to the current schedule.rb file. You can replace the <code>#{application}</code> with any identifying string you'd like. You can have any number of apps deploy to the same crontab file peacefully given they each use a different identifier.
-
-If you wish to simply overwrite your crontab file each time you deploy, use the <code>--write-crontab</code> option. This is ideal if you are only working with one app and every crontab entry is contained in a single schedule.rb file.
-
-By mixing and matching the <code>--load-file</code> and <code>--user</code> options with your various :roles in Capistrano it is entirely possible to deploy different crontab schedules under different users to all your various servers. Get creative!
-
-If you want to override a variable (like your environment) at the time of deployment you can do so with the <code>--set</code> option: http://wiki.github.com/javan/whenever/setting-variables-on-the-fly
-
-== Credit
-
-Whenever was created for use at Inkling (http://inklingmarkets.com) where I work. Their take on it: http://blog.inklingmarkets.com/2009/02/whenever-easy-way-to-do-cron-jobs-from.html
-
-While building Whenever, I learned a lot by digging through the source code of Capistrano - http://github.com/jamis/capistrano
-
-== Discussion / Feedback / Issues / Bugs
-
-For general discussion and questions, please use the google group: http://groups.google.com/group/whenever-gem
-
-If you've found a genuine bug or issue, please use the Issues section on github: http://github.com/javan/whenever/issues
-
-== License
-
-Copyright (c) 2009 Javan Makhmali
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the "Software"), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
View
32 vendor/gems/whenever-0.4.1/Rakefile
@@ -1,32 +0,0 @@
-require 'rubygems'
-require 'rake'
-
-require 'lib/whenever/version.rb'
-
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gemspec|
- gemspec.name = "whenever"
- gemspec.version = Whenever::VERSION
- gemspec.summary = "Clean ruby syntax for defining and deploying messy cron jobs."
- gemspec.description = "Clean ruby syntax for defining and deploying messy cron jobs."
- gemspec.email = "javan@javan.us"
- gemspec.homepage = "http://github.com/javan/whenever"
- gemspec.authors = ["Javan Makhmali"]
- gemspec.add_dependency("chronic", '>= 0.2.3')
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
-end
-
-require 'rake/testtask'
-Rake::TestTask.new(:test) do |test|
- test.libs << 'lib' << 'test'
- test.pattern = 'test/*.rb'
- test.verbose = true
-end
-
-task :test => :check_dependencies
-
-task :default => :test
View
30 vendor/gems/whenever-0.4.1/bin/whenever
@@ -1,30 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rubygems'
-require 'optparse'
-require 'fileutils'
-require 'tempfile'
-require 'whenever'
-
-options = Hash.new
-
-OptionParser.new do |opts|
- opts.banner = "Usage: whenever [options]"
- opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION}"; exit(0) }
- opts.on('-w', '--write-crontab') { options[:write] = true }
- opts.on('-i', '--update-crontab [identifier]', 'Default: full path to schedule.rb file') do |identifier|
- options[:update] = true
- options[:identifier] = identifier if identifier
- end
- opts.on('-f', '--load-file [schedule file]', 'Default: config/schedule.rb') do |file|
- options[:file] = file if file
- end
- opts.on('-u', '--user [user]', 'Default: current user') do |user|
- options[:user] = user if user
- end
- opts.on('-s', '--set [variables]', 'Example: --set environment=staging&path=/my/sweet/path') do |set|
- options[:set] = set if set
- end
-end.parse!
-
-Whenever::CommandLine.execute(options)
View
69 vendor/gems/whenever-0.4.1/bin/wheneverize
@@ -1,69 +0,0 @@
-#!/usr/bin/env ruby
-
-# This file is based heavily on Capistrano's `capify` command
-
-require 'optparse'
-require 'fileutils'
-
-OptionParser.new do |opts|
- opts.banner = "Usage: #{File.basename($0)} [path]"
-
- begin
- opts.parse!(ARGV)
- rescue OptionParser::ParseError => e
- warn e.message
- puts opts
- exit 1
- end
-end
-
-if ARGV.empty?
- abort "Please specify the directory to wheneverize, e.g. `#{File.basename($0)} .'"
-elsif !File.exists?(ARGV.first)
- abort "`#{ARGV.first}' does not exist."
-elsif !File.directory?(ARGV.first)
- abort "`#{ARGV.first}' is not a directory."
-elsif ARGV.length > 1
- abort "Too many arguments; please specify only the directory to wheneverize."
-end
-
-
-content = <<-FILE
-# Use this file to easily define all of your cron jobs.
-#
-# It's helpful, but not entirely necessary to understand cron before proceeding.
-# http://en.wikipedia.org/wiki/Cron
-
-# Example:
-#
-# set :output, "/path/to/my/cron_log.log"
-#
-# every 2.hours do
-# command "/usr/bin/some_great_command"
-# runner "MyModel.some_method"
-# rake "some:great:rake:task"
-# end
-#
-# every 4.days do
-# runner "AnotherModel.prune_old_records"
-# end
-
-# Learn more: http://github.com/javan/whenever
-FILE
-
-file = 'config/schedule.rb'
-base = ARGV.shift
-
-file = File.join(base, file)
-if File.exists?(file)
- warn "[skip] `#{file}' already exists"
-elsif File.exists?(file.downcase)
- warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
-elsif !File.exists?(File.dirname(file))
- warn "[skip] directory `#{File.dirname(file)}' does not exist"
-else
- puts "[add] writing `#{file}'"
- File.open(file, "w") { |f| f.write(content) }
-end
-
-puts "[done] wheneverized!"
View
31 vendor/gems/whenever-0.4.1/lib/whenever.rb
@@ -1,31 +0,0 @@
-require 'chronic'
-
-# Hoping to load Rails' Rakefile
-begin
- load 'Rakefile'
-rescue LoadError
- nil
-end
-
-# If Rails' rakefile was loaded than so was active_support, but
-# if this is being used in a non-rails enviroment we need to require it.
-# It was previously defined as a dependency of this gem, but that became
-# problematic. See: http://github.com/javan/whenever/issues#issue/1
-begin
- require 'active_support'
-rescue LoadError
- warn 'To user Whenever you need the active_support gem:'
- warn '$ sudo gem install active_support'
- exit(1)
-end
-
-# Whenever files
-require 'whenever/base'
-require 'whenever/job_list'
-require 'whenever/job_types/default'
-require 'whenever/job_types/rake_task'
-require 'whenever/job_types/runner'
-require 'whenever/outputs/cron'
-require 'whenever/outputs/cron/output_redirection'
-require 'whenever/command_line'
-require 'whenever/version'
View
15 vendor/gems/whenever-0.4.1/lib/whenever/base.rb
@@ -1,15 +0,0 @@
-module Whenever
-
- def self.cron(options)
- Whenever::JobList.new(options).generate_cron_output
- end
-
- def self.path
- if defined?(RAILS_ROOT)
- RAILS_ROOT
- elsif defined?(::RAILS_ROOT)
- ::RAILS_ROOT
- end
- end
-
-end
View
108 vendor/gems/whenever-0.4.1/lib/whenever/command_line.rb
@@ -1,108 +0,0 @@
-module Whenever
- class CommandLine
-
- def self.execute(options={})
- new(options).run
- end
-
- def initialize(options={})
- @options = options
-
- @options[:file] ||= 'config/schedule.rb'
- @options[:identifier] ||= default_identifier
-
- unless File.exists?(@options[:file])
- warn("[fail] Can't find file: #{@options[:file]}")
- exit(1)
- end
-
- if @options[:update] && @options[:write]
- warn("[fail] Can't update AND write. choose one.")
- exit(1)
- end
- end
-
- def run
- if @options[:update]
- write_crontab(updated_crontab)
- elsif @options[:write]
- write_crontab(whenever_cron)
- else
- puts Whenever.cron(@options)
- exit(0)
- end
- end
-
- protected
-
- def default_identifier
- File.expand_path(@options[:file])
- end
-
- def whenever_cron
- @whenever_cron ||= [comment_open, Whenever.cron(@options), comment_close].join("\n") + "\n"
- end
-
- def read_crontab
- return @current_crontab if @current_crontab
-
- command = ['crontab -l']
- command << "-u #{@options[:user]}" if @options[:user]
-
- command_results = %x[#{command.join(' ')} 2> /dev/null]
- @current_crontab = $?.exitstatus.zero? ? command_results : ''
- end
-
- def write_crontab(contents)
- tmp_cron_file = Tempfile.new('whenever_tmp_cron').path
- File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file|
- file << contents
- end
-
- command = ['crontab']
- command << "-u #{@options[:user]}" if @options[:user]
- command << tmp_cron_file
-
- if system(command.join(' '))
- action = 'written' if @options[:write]
- action = 'updated' if @options[:update]
- puts "[write] crontab file #{action}"
- exit(0)
- else
- warn "[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid."
- exit(1)
- end
- end
-
- def updated_crontab
- # Check for unopened or unclosed identifier blocks
- if read_crontab.index(comment_open) && !read_crontab.index(comment_close)
- warn "[fail] Unclosed indentifier; Your crontab file contains '#{comment_open}', but no '#{comment_close}'"
- exit(1)
- elsif !read_crontab.index(comment_open) && read_crontab.index(comment_close)
- warn "[fail] Unopened indentifier; Your crontab file contains '#{comment_close}', but no '#{comment_open}'"
- exit(1)
- end
-
- # If an existing identier block is found, replace it with the new cron entries
- if read_crontab.index(comment_open) && read_crontab.index(comment_close)
- read_crontab.gsub(Regexp.new("#{comment_open}.+#{comment_close}", Regexp::MULTILINE), whenever_cron.chomp)
- else # Otherwise, append the new cron entries after any existing ones
- [read_crontab, whenever_cron].join("\n\n")
- end
- end
-
- def comment_base
- "Whenever generated tasks for: #{@options[:identifier]}"
- end
-
- def comment_open
- "# Begin #{comment_base}"
- end
-
- def comment_close
- "# End #{comment_base}"
- end
-
- end
-end
View
161 vendor/gems/whenever-0.4.1/lib/whenever/job_list.rb
@@ -1,161 +0,0 @@
-module Whenever
- class JobList
-
- def initialize(options)
- @jobs = Hash.new
- @env = Hash.new
-
- case options
- when String
- config = options
- when Hash
- config = if options[:string]
- options[:string]
- elsif options[:file]
- File.read(options[:file])
- end
- pre_set(options[:set])
- end
-
- eval(config)
- end
-
- def set(variable, value)
- return if instance_variable_defined?("@#{variable}".to_sym)
-
- instance_variable_set("@#{variable}".to_sym, value)
- self.class.send(:attr_reader, variable.to_sym)
- end
-
- def env(variable, value)
- @env[variable.to_s] = value
- end
-
- def every(frequency, options = {})
- @current_time_scope = frequency
- @options = options
- yield
- end
-
- def command(task, options = {})
- # :cron_log was an old option for output redirection, it remains for backwards compatibility
- options[:output] = (options[:cron_log] || @cron_log) if defined?(@cron_log) || options.has_key?(:cron_log)
- # :output is the newer, more flexible option.
- options[:output] = @output if defined?(@output) && !options.has_key?(:output)
- options[:class] ||= Whenever::Job::Default
- @jobs[@current_time_scope] ||= []
- @jobs[@current_time_scope] << options[:class].new(@options.merge(:task => task).merge(options))
- end
-
- def runner(task, options = {})
- options.reverse_merge!(:environment => @environment, :path => @path)
- options[:class] = Whenever::Job::Runner
- command(task, options)
- end
-
- def rake(task, options = {})
- options.reverse_merge!(:environment => @environment, :path => @path)
- options[:class] = Whenever::Job::RakeTask
- command(task, options)
- end
-
- def generate_cron_output
- set_path_environment_variable
-
- [environment_variables, cron_jobs].compact.join
- end
-
- private
-
- #
- # Takes a string like: "variable1=something&variable2=somethingelse"
- # and breaks it into variable/value pairs. Used for setting variables at runtime from the command line.
- # Only works for setting values as strings.
- #
- def pre_set(variable_string = nil)
- return if variable_string.blank?
-
- pairs = variable_string.split('&')
- pairs.each do |pair|
- next unless pair.index('=')
- variable, value = *pair.split('=')
- set(variable.strip, value.strip) unless variable.blank? || value.blank?
- end
- end
-
- def set_path_environment_variable
- return if path_should_not_be_set_automatically?
- @env[:PATH] = read_path unless read_path.blank?
- end
-
- def read_path
- ENV['PATH'] if ENV
- end
-
- def path_should_not_be_set_automatically?
- @set_path_automatically === false || @env[:PATH] || @env["PATH"]
- end
-
- def environment_variables
- return if @env.empty?
-
- output = []
- @env.each do |key, val|
- output << "#{key}=#{val}\n"
- end
- output << "\n"
-
- output.join
- end
-
- #
- # Takes the standard cron output that Whenever generates and finds
- # similar entries that can be combined. For example: If a job should run
- # at 3:02am and 4:02am, instead of creating two jobs this method combines
- # them into one that runs on the 2nd minute at the 3rd and 4th hour.
- #
- def combine(entries)
- entries.map! { |entry| entry.split(/ +/, 6) }
- 0.upto(4) do |f|
- (entries.length-1).downto(1) do |i|
- next if entries[i][f] == '*'
- comparison = entries[i][0...f] + entries[i][f+1..-1]
- (i-1).downto(0) do |j|
- next if entries[j][f] == '*'
- if comparison == entries[j][0...f] + entries[j][f+1..-1]
- entries[j][f] += ',' + entries[i][f]
- entries.delete_at(i)
- break
- end
- end
- end
- end
-
- entries.map { |entry| entry.join(' ') }
- end
-
- def cron_jobs
- return if @jobs.empty?
-
- shortcut_jobs = []
- regular_jobs = []
-
- @jobs.each do |time, jobs|
- jobs.each do |job|
- Whenever::Output::Cron.output(time, job) do |cron|
- cron << "\n\n"
-
- if cron.starts_with?("@")
- shortcut_jobs << cron
- else
- regular_jobs << cron
- end
- end
- end
- end
-
- shortcut_jobs.join + combine(regular_jobs).join
- end
-
- end
-end
View
27 vendor/gems/whenever-0.4.1/lib/whenever/job_types/default.rb
@@ -1,27 +0,0 @@
-module Whenever
- module Job
- class Default
-
- attr_accessor :task, :at, :output, :output_redirection
-
- def initialize(options = {})
- @task = options[:task]
- @at = options[:at]
- @output_redirection = options.has_key?(:output) ? options[:output] : :not_set
- @environment = options[:environment] || :production
- @path = options[:path] || Whenever.path
- end
-
- def output
- task
- end
-
- protected
-
- def path_required
- raise ArgumentError, "No path available; set :path, '/your/path' in your schedule file" if @path.blank?
- end
-
- end
- end
-end
View
12 vendor/gems/whenever-0.4.1/lib/whenever/job_types/rake_task.rb
@@ -1,12 +0,0 @@
-module Whenever
- module Job
- class RakeTask < Whenever::Job::Default
-
- def output
- path_required
- "cd #{@path} && RAILS_ENV=#{@environment} /usr/bin/env rake #{task}"
- end
-
- end
- end
-end
View
12 vendor/gems/whenever-0.4.1/lib/whenever/job_types/runner.rb
@@ -1,12 +0,0 @@
-module Whenever
- module Job
- class Runner < Whenever::Job::Default
-
- def output
- path_required
- %Q(#{File.join(@path, 'script', 'runner')} -e #{@environment} #{task.inspect})
- end
-
- end
- end
-end
View
139 vendor/gems/whenever-0.4.1/lib/whenever/outputs/cron.rb
@@ -1,139 +0,0 @@
-module Whenever
- module Output
-
- class Cron
-
- attr_accessor :time, :task
-
- def initialize(time = nil, task = nil, at = nil, output_redirection = nil)
- @time = time
- @task = task
- @at = at.is_a?(String) ? (Chronic.parse(at) || 0) : (at || 0)
- @output_redirection = output_redirection
- end
-
- def self.enumerate(item)
- if item and item.is_a?(String)
- items = item.split(',')
- else
- items = item
- items = [items] unless items and items.respond_to?(:each)
- end
- items
- end
-
- def self.output(times, job)
- enumerate(times).each do |time|
- enumerate(job.at).each do |at|
- yield new(time, job.output, at, job.output_redirection).output
- end
- end
- end
-
- def output
- [time_in_cron_syntax, task, output_redirection].compact.join(' ').strip
- end
-
- def time_in_cron_syntax
- case @time
- when Symbol then parse_symbol
- when String then parse_as_string
- else parse_time
- end
- end
-
- def output_redirection
- OutputRedirection.new(@output_redirection).to_s unless @output_redirection == :not_set
- end
-
- protected
-
- def parse_symbol
- shortcut = case @time
- when :reboot then '@reboot'
- when :year, :yearly then '@annually'
- when :day, :daily then '@daily'
- when :midnight then '@midnight'
- when :month, :monthly then '@monthly'
- when :week, :weekly then '@weekly'
- when :hour, :hourly then '@hourly'
- end
-
- if shortcut
- if @at > 0
- raise ArgumentError, "You cannot specify an ':at' when using the shortcuts for times."
- else
- return shortcut
- end
- else
- parse_as_string
- end
- end
-
- def parse_time
- timing = Array.new(5, '*')
- case @time
- when 0.seconds...1.minute
- raise ArgumentError, "Time must be in minutes or higher"
- when 1.minute...1.hour
- minute_frequency = @time / 60
- timing[0] = comma_separated_timing(minute_frequency, 59)
- when 1.hour...1.day
- hour_frequency = (@time / 60 / 60).round
- timing[0] = @at.is_a?(Time) ? @at.min : @at
- timing[1] = comma_separated_timing(hour_frequency, 23)
- when 1.day...1.month
- day_frequency = (@time / 24 / 60 / 60).round
- timing[0] = @at.is_a?(Time) ? @at.min : 0
- timing[1] = @at.is_a?(Time) ? @at.hour : @at
- timing[2] = comma_separated_timing(day_frequency, 31, 1)
- when 1.month..12.months
- month_frequency = (@time / 30 / 24 / 60 / 60).round
- timing[0] = @at.is_a?(Time) ? @at.min : 0
- timing[1] = @at.is_a?(Time) ? @at.hour : 0
- timing[2] = @at.is_a?(Time) ? @at.day : (@at.zero? ? 1 : @at)
- timing[3] = comma_separated_timing(month_frequency, 12, 1)
- else
- return parse_as_string
- end
- timing.join(' ')
- end
-
- def parse_as_string
- return unless @time
- string = @time.to_s
-
- timing = Array.new(4, '*')
- timing[0] = @at.is_a?(Time) ? @at.min : 0
- timing[1] = @at.is_a?(Time) ? @at.hour : 0
-
- return (timing << '1-5') * " " if string.downcase.index('weekday')
- return (timing << '6,0') * " " if string.downcase.index('weekend')
-
- %w(sun mon tue wed thu fri sat).each_with_index do |day, i|
- return (timing << i) * " " if string.downcase.index(day)
- end
-
- raise ArgumentError, "Couldn't parse: #{@time}"
- end
-
- def comma_separated_timing(frequency, max, start = 0)
- return start if frequency.blank? || frequency.zero?
- return '*' if frequency == 1
- return frequency if frequency > (max * 0.5).ceil
-
- original_start = start
-
- start += frequency unless (max + 1).modulo(frequency).zero? || start > 0
- output = (start..max).step(frequency).to_a
-
- max_occurances = (max.to_f / (frequency.to_f)).round
- max_occurances += 1 if original_start.zero?
-
- output[0, max_occurances].join(',')
- end
-
- end
-
- end
-end
View
54 vendor/gems/whenever-0.4.1/lib/whenever/outputs/cron/output_redirection.rb
@@ -1,54 +0,0 @@
-module Whenever
- module Output
- class Cron
- class OutputRedirection
-
- def initialize(output)
- @output = output
- end
-
- def to_s
- return '' unless defined?(@output)
- case @output
- when String then redirect_from_string
- when Hash then redirect_from_hash
- when NilClass then ">> /dev/null 2>&1"
- else ''
- end
- end
-
- protected
-
- def stdout
- return unless @output.has_key?(:standard)
- @output[:standard].nil? ? '/dev/null' : @output[:standard]
- end
-
- def stderr
- return unless @output.has_key?(:error)
- @output[:error].nil? ? '/dev/null' : @output[:error]
- end
-
- def redirect_from_hash
- case
- when stdout == '/dev/null' && stderr == '/dev/null'
- ">> /dev/null 2>&1"
- when stdout && stderr
- ">> #{stdout} 2> #{stderr}"
- when stderr
- "2> #{stderr}"
- when stdout
- ">> #{stdout}"
- else
- ''
- end
- end
-
- def redirect_from_string
- ">> #{@output} 2>&1"
- end
-
- end
- end
- end
-end
View
3  vendor/gems/whenever-0.4.1/lib/whenever/version.rb
@@ -1,3 +0,0 @@
-module Whenever
- VERSION = '0.4.1'
-end unless defined?(Whenever::VERSION)
View
101 vendor/gems/whenever-0.4.1/test/command_line_test.rb
@@ -1,101 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/test_helper")
-
-class CommandLineTest < Test::Unit::TestCase
-
- context "A command line write" do
- setup do
- File.expects(:exists?).with('config/schedule.rb').returns(true)
- @command = Whenever::CommandLine.new(:write => true, :identifier => 'My identifier')
- @task = "#{two_hours} /my/command"
- Whenever.expects(:cron).returns(@task)
- end
-
- should "output the cron job with identifier blocks" do
- output = <<-EXPECTED
-# Begin Whenever generated tasks for: My identifier
-#{@task}
-# End Whenever generated tasks for: My identifier
-EXPECTED
-
- assert_equal output, @command.send(:whenever_cron)
- end
-
- should "write the crontab when run" do
- @command.expects(:write_crontab).returns(true)
- assert @command.run
- end
- end
-
- context "A command line update" do
- setup do
- File.expects(:exists?).with('config/schedule.rb').returns(true)
- @command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
- @task = "#{two_hours} /my/command"
- Whenever.expects(:cron).returns(@task)
- end
-
- should "add the cron to the end of the file if there is no existing identifier block" do
- existing = '# Existing crontab'
- @command.expects(:read_crontab).at_least_once.returns(existing)
-
- new_cron = <<-EXPECTED
-#{existing}
-
-# Begin Whenever generated tasks for: My identifier
-#{@task}
-# End Whenever generated tasks for: My identifier
-EXPECTED
-
- assert_equal new_cron, @command.send(:updated_crontab)
-
- @command.expects(:write_crontab).with(new_cron).returns(true)
- assert @command.run
- end
-
- should "replace an existing block if the identifier matches" do
- existing = <<-EXISTING_CRON
-# Something
-
-# Begin Whenever generated tasks for: My identifier
-My whenever job that was already here
-# End Whenever generated tasks for: My identifier
-
-# Begin Whenever generated tasks for: Other identifier
-This shouldn't get replaced
-# End Whenever generated tasks for: Other identifier
-EXISTING_CRON
-
- @command.expects(:read_crontab).at_least_once.returns(existing)
-
- new_cron = <<-NEW_CRON
-# Something
-
-# Begin Whenever generated tasks for: My identifier
-#{@task}
-# End Whenever generated tasks for: My identifier
-
-# Begin Whenever generated tasks for: Other identifier
-This shouldn't get replaced
-# End Whenever generated tasks for: Other identifier
-NEW_CRON
-
- assert_equal new_cron, @command.send(:updated_crontab)
-
- @command.expects(:write_crontab).with(new_cron).returns(true)
- assert @command.run
- end
- end
-
- context "A command line update with no identifier" do
- setup do
- File.expects(:exists?).with('config/schedule.rb').returns(true)
- Whenever::CommandLine.any_instance.expects(:default_identifier).returns('DEFAULT')
- @command = Whenever::CommandLine.new(:update => true, :file => @file)
- end
-
- should "use the default identifier" do
- assert_equal "Whenever generated tasks for: DEFAULT", @command.send(:comment_base)
- end
- end
-
-end
View
226 vendor/gems/whenever-0.4.1/test/cron_test.rb
@@ -1,226 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/test_helper")
-
-class CronTest < Test::Unit::TestCase
-
- context "When parsing time in minutes" do
- should "raise if less than 1 minute" do
- assert_raises ArgumentError do
- parse_time(59.seconds)
- end
-
- assert_raises ArgumentError do
- parse_time(0.minutes)
- end
- end
-
- # For santity, do some tests on straight String
- should "parse correctly" do
- assert_equal '* * * * *', parse_time(1.minute)
- assert_equal '0,5,10,15,20,25,30,35,40,45,50,55 * * * *', parse_time(5.minutes)
- assert_equal '7,14,21,28,35,42,49,56 * * * *', parse_time(7.minutes)
- assert_equal '0,30 * * * *', parse_time(30.minutes)
- assert_equal '32 * * * *', parse_time(32.minutes)
- assert_not_equal '60 * * * *', parse_time(60.minutes) # 60 minutes bumps up into the hour range
- end
-
- # Test all minutes
- (2..59).each do |num|
- should "parse correctly for #{num} minutes" do
- start = 0
- start += num unless 60.modulo(num).zero?
- minutes = (start..59).step(num).to_a
-
- assert_equal "#{minutes.join(',')} * * * *", parse_time(num.minutes)
- end
- end
- end
-
- context "When parsing time in hours" do
- should "parse correctly" do
- assert_equal '0 * * * *', parse_time(1.hour)
- assert_equal '0 0,2,4,6,8,10,12,14,16,18,20,22 * * *', parse_time(2.hours)
- assert_equal '0 0,3,6,9,12,15,18,21 * * *', parse_time(3.hours)
- assert_equal '0 5,10,15,20 * * *', parse_time(5.hours)
- assert_equal '0 17 * * *', parse_time(17.hours)
- assert_not_equal '0 24 * * *', parse_time(24.hours) # 24 hours bumps up into the day range
- end
-
- (2..23).each do |num|
- should "parse correctly for #{num} hours" do
- start = 0
- start += num unless 24.modulo(num).zero?
- hours = (start..23).step(num).to_a
-
- assert_equal "0 #{hours.join(',')} * * *", parse_time(num.hours)
- end
- end
-
- should "parse correctly when given an 'at' with minutes as an Integer" do
- assert_minutes_equals "1", 1
- assert_minutes_equals "14", 14
- assert_minutes_equals "27", 27
- assert_minutes_equals "55", 55
- end
-
- should "parse correctly when given an 'at' with minutes as a Time" do
- # Basically just testing that Chronic parses some times and we get the minutes out of it
- assert_minutes_equals "1", '3:01am'
- assert_minutes_equals "1", 'January 21 2:01 PM'
- assert_minutes_equals "0", 'midnight'
- assert_minutes_equals "59", '13:59'
- end
- end
-
- context "When parsing time in days (of month)" do
- should "parse correctly" do
- assert_equal '0 0 * * *', parse_time(1.days)
- assert_equal '0 0 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * *', parse_time(2.days)
- assert_equal '0 0 1,5,9,13,17,21,25,29 * *', parse_time(4.days)
- assert_equal '0 0 1,8,15,22 * *', parse_time(7.days)
- assert_equal '0 0 1,17 * *', parse_time(16.days)
- assert_equal '0 0 17 * *', parse_time(17.days)
- assert_equal '0 0 29 * *', parse_time(29.days)
- assert_not_equal '0 0 30 * *', parse_time(30.days) # 30 days bumps into the month range
- end
-
- should "parse correctly when given an 'at' with hours, minutes as a Time" do
- # first param is an array with [hours, minutes]
- assert_hours_and_minutes_equals %w(3 45), '3:45am'
- assert_hours_and_minutes_equals %w(20 1), '8:01pm'
- assert_hours_and_minutes_equals %w(0 0), 'midnight'
- assert_hours_and_minutes_equals %w(1 23), '1:23 AM'
- assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
- end
-
- should "parse correctly when given an 'at' with hours as an Integer" do
- # first param is an array with [hours, minutes]
- assert_hours_and_minutes_equals %w(1 0), 1
- assert_hours_and_minutes_equals %w(3 0), 3
- assert_hours_and_minutes_equals %w(15 0), 15
- assert_hours_and_minutes_equals %w(19 0), 19
- assert_hours_and_minutes_equals %w(23 0), 23
- end
- end
-
- context "When parsing time in months" do
- should "parse correctly" do
- assert_equal '0 0 1 * *', parse_time(1.month)
- assert_equal '0 0 1 1,3,5,7,9,11 *', parse_time(2.months)
- assert_equal '0 0 1 1,4,7,10 *', parse_time(3.months)
- assert_equal '0 0 1 1,5,9 *', parse_time(4.months)
- assert_equal '0 0 1 1,6 *', parse_time(5.months)
- assert_equal '0 0 1 7 *', parse_time(7.months)
- assert_equal '0 0 1 8 *', parse_time(8.months)
- assert_equal '0 0 1 9 *', parse_time(9.months)
- assert_equal '0 0 1 10 *', parse_time(10.months)
- assert_equal '0 0 1 11 *', parse_time(11.months)
- assert_equal '0 0 1 12 *', parse_time(12.months)
- end
-
- should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
- # first param is an array with [days, hours, minutes]
- assert_days_and_hours_and_minutes_equals %w(1 3 45), 'January 1st 3:45am'
- assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'
- assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'
- assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
- end
-
- should "parse correctly when given an 'at' with days as an Integer" do
- # first param is an array with [days, hours, minutes]
- assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
- assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
- assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
- end
- end
-
- context "When parsing time in days (of week)" do
- should "parse days of the week correctly" do
- {
- '0' => %w(sun Sunday SUNDAY SUN),
- '1' => %w(mon Monday MONDAY MON),
- '2' => %w(tue tues Tuesday TUESDAY TUE),
- '3' => %w(wed Wednesday WEDNESDAY WED),
- '4' => %w(thu thurs thur Thursday THURSDAY THU),
- '5' => %w(fri Friday FRIDAY FRI),
- '6' => %w(sat Saturday SATURDAY SAT)
- }.each do |day, day_tests|
- day_tests.each do |day_test|
- assert_equal "0 0 * * #{day}", parse_time(day_test)
- end
- end
- end
-
- should "allow additional directives" do
- assert_equal '30 13 * * 5', parse_time('friday', nil, "1:30 pm")
- assert_equal '22 2 * * 1', parse_time('Monday', nil, "2:22am")
- assert_equal '55 17 * * 4', parse_time('THU', nil, "5:55PM")
- end
-
- should "parse weekday correctly" do
- assert_equal '0 0 * * 1-5', parse_time('weekday')
- assert_equal '0 0 * * 1-5', parse_time('Weekdays')
- assert_equal '0 1 * * 1-5', parse_time('Weekdays', nil, "1:00 am")
- assert_equal '59 5 * * 1-5', parse_time('Weekdays', nil, "5:59 am")
- end
-
- should "parse weekend correctly" do
- assert_equal '0 0 * * 6,0', parse_time('weekend')
- assert_equal '0 0 * * 6,0', parse_time('Weekends')
- assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, "7am")
- assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, "6:02PM")
- end
- end
-
- context "When parsing time using the cron shortcuts" do
- should "parse a :symbol into the correct shortcut" do
- assert_equal '@reboot', parse_time(:reboot)
- assert_equal '@annually', parse_time(:year)
- assert_equal '@annually', parse_time(:yearly)
- assert_equal '@daily', parse_time(:day)
- assert_equal '@daily', parse_time(:daily)
- assert_equal '@midnight', parse_time(:midnight)
- assert_equal '@monthly', parse_time(:month)
- assert_equal '@monthly', parse_time(:monthly)
- assert_equal '@hourly', parse_time(:hour)
- assert_equal '@hourly', parse_time(:hourly)
- end
-
- should "raise an exception if a valid shortcut is given but also an :at" do
- assert_raises ArgumentError do
- parse_time(:hour, nil, "1:00 am")
- end
-
- assert_raises ArgumentError do
- parse_time(:reboot, nil, 5)
- end
-
- assert_raises ArgumentError do
- parse_time(:day, nil, '4:20pm')
- end
- end
- end
-
-private
-
- def assert_days_and_hours_and_minutes_equals(expected, time)
- cron = parse_time(2.months, 'some task', time)
- minutes, hours, days, *garbage = cron.split(' ')
- assert_equal expected, [days, hours, minutes]
- end
-
- def assert_hours_and_minutes_equals(expected, time)
- cron = parse_time(2.days, 'some task', time)
- minutes, hours, *garbage = cron.split(' ')
- assert_equal expected, [hours, minutes]
- end
-
- def assert_minutes_equals(expected, time)
- cron = parse_time(2.hours, 'some task', time)
- assert_equal expected, cron.split(' ')[0]
- end
-
- def parse_time(time = nil, task = nil, at = nil)
- Whenever::Output::Cron.new(time, task, at).time_in_cron_syntax
- end
-
-end
View
178 vendor/gems/whenever-0.4.1/test/output_at_test.rb
@@ -1,178 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/test_helper")
-
-class OutputAtTest < Test::Unit::TestCase
-
- context "weekday at a (single) given time" do
- setup do
- @output = Whenever.cron \
- <<-file
- every "weekday", :at => '5:02am' do
- command "blahblah"
- end
- file
- end
-
- should "output the command using that time" do
- assert_match '2 5 * * 1-5 blahblah', @output
- end
- end
-
- context "weekday at a multiple diverse times, via an array" do
- setup do
- @output = Whenever.cron \
- <<-file
- every "weekday", :at => %w(5:02am 3:52pm) do
- command "blahblah"
- end
- file
- end
-
- should "output the commands for both times given" do
- assert_match '2 5 * * 1-5 blahblah', @output
- assert_match '52 15 * * 1-5 blahblah', @output
- end
- end
-
- context "weekday at a multiple diverse times, comma separated" do
- setup do
- @output = Whenever.cron \
- <<-file
- every "weekday", :at => '5:02am, 3:52pm' do
- command "blahblah"
- end
- file
- end
-
- should "output the commands for both times given" do
- assert_match '2 5 * * 1-5 blahblah', @output
- assert_match '52 15 * * 1-5 blahblah', @output
- end
- end
-
- context "weekday at a multiple aligned times" do
- setup do
- @output = Whenever.cron \
- <<-file
- every "weekday", :at => '5:02am, 3:02pm' do
- command "blahblah"
- end
- file
- end
-
- should "output the command using one entry because the times are aligned" do
- assert_match '2 5,15 * * 1-5 blahblah', @output
- end
- end
-
- context "various days at a various aligned times" do
- setup do
- @output = Whenever.cron \
- <<-file
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
- command "blahblah"
- end
- file
- end
-
- should "output the command using one entry because the times are aligned" do
- assert_match '2 5,15 * * 1,3,5 blahblah', @output
- end
- end
-
- context "various days at a various aligned times using a runner" do
- setup do
- @output = Whenever.cron \
- <<-file
- set :path, '/your/path'
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
- runner "blahblah"
- end
- file
- end
-
- should "output the runner using one entry because the times are aligned" do
- assert_match '2 5,15 * * 1,3,5 /your/path/script/runner -e production "blahblah"', @output
- end
- end
-
- context "various days at a various aligned times using a rake task" do
- setup do
- @output = Whenever.cron \
- <<-file
- set :path, '/your/path'
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
- rake "blah:blah"
- end
- file
- end
-
- should "output the rake task using one entry because the times are aligned" do
- assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output
- end
- end
-
- context "A command every 1.month at very diverse times" do
- setup do
- @output = Whenever.cron \
- <<-file
- every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
- command "blahblah"
- end
- file
- end
-
- should "output 6 commands since none align" do
- # The 1.month commands
- assert_match '2 5 1 * * blahblah', @output
- assert_match '22 14 17 * * blahblah', @output
- assert_match '33 3 3 * * blahblah', @output
-
- # The 1.day commands
- assert_match '2 5 * * * blahblah', @output
- assert_match '22 14 * * * blahblah', @output
- assert_match '33 3 * * * blahblah', @output
- end
- end
-
- context "Multiple commands output every :reboot" do
- setup do
- @output = Whenever.cron \
- <<-file
- every :reboot do
- command "command_1"
- command "command_2"
- end
- file
- end
-
- should "output both commands @reboot" do
- assert_match "@reboot command_1", @output
- assert_match "@reboot command_2", @output
- end
- end
-
- context "Many different job types output every :day" do
- setup do
- @output = Whenever.cron \
- <<-file
- set :path, '/your/path'
- every :day do
- rake "blah:blah"
- runner "runner_1"
- command "command_1"
- runner "runner_2"
- command "command_2"
- end
- file
- end
-
- should "output all of the commands @daily" do
- assert_match '@daily cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output
- assert_match '@daily /your/path/script/runner -e production "runner_1"', @output
- assert_match '@daily command_1', @output
- assert_match '@daily /your/path/script/runner -e production "runner_2"', @output
- assert_match '@daily command_2', @output
- end
- end
-
-end
View
37 vendor/gems/whenever-0.4.1/test/output_command_test.rb
@@ -1,37 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + "/test_helper")
-
-class OutputCommandTest < Test::Unit::TestCase
-
- context "A plain command" do
- setup do
- @output = Whenever.cron \
- <<-file
- every 2.hours do
- command "blahblah"
- end
- file
- end
-
- should "output the command" do
- assert_match /^.+ .+ .+ .+ blahblah$/, @output