diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index c56d63f..3c48b42 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,8 @@ +== 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] diff --git a/README.rdoc b/README.rdoc index 443fe2b..502688b 100644 --- a/README.rdoc +++ b/README.rdoc @@ -14,14 +14,14 @@ In a Rails (2.1 or greater) application: in your "config/environment.rb" file: Rails::Initializer.run do |config| - config.gem 'javan-whenever', :lib => false, :version => '>= 0.1.3' :source => 'http://gems.github.com' + config.gem 'javan-whenever', :lib => false, :version => '>= 0.1.4' :source => 'http://gems.github.com' end To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary). In older versions of Rails: - $ gem sources -a http://gems.github.com + $ gem sources -a http://gems.github.com (you only need to run this once) $ gem install javan-whenever in your "config/environment.rb" file: @@ -81,7 +81,7 @@ in your "config/deploy.rb" file do something like: namespace :deploy do desc "write the crontab file" task :write_crontab, :roles => :app do - run "cd #{release_path} && whenever -c" + run "cd #{release_path} && whenever --write-crontab" end end diff --git a/bin/whenever b/bin/whenever index a1f512d..461033d 100644 --- a/bin/whenever +++ b/bin/whenever @@ -1,17 +1,54 @@ #!/usr/bin/env ruby -require 'rake' +require 'rubygems' require 'optparse' +require 'fileutils' +require 'tempfile' require 'whenever' require File.expand_path(File.dirname(__FILE__) + "/../lib/version") -task = "whenever:output_cron" - +options = Hash.new + OptionParser.new do |opts| opts.banner = "Usage: whenever [options]" - opts.on('-c', '--write-crontab') { task = "whenever:write_cron" } opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION::STRING}"; exit } + opts.on('-w', '--write-crontab') { options[:write] = true } + 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 end.parse! -Rake::Task[task].invoke \ No newline at end of file +options[:file] ||= 'config/schedule.rb' + +unless File.exists?(options[:file]) + warn("[fail] can't find file: #{options[:file]}") + exit(1) +end + +if options[:write] + cron_output = Whenever.cron(:file => options[:file]) + tmp_cron_file = Tempfile.new('whenever_tmp_cron').path + File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file| + file << cron_output + end + + command = ['crontab'] + command << "-u #{options[:user]}" if options[:user] + command << tmp_cron_file + + if system(command.join(' ')) + puts "[write] crontab file updated" + exit + else + warn "[fail] couldn't write crontab" + exit(1) + end + +else + puts Whenever.cron(:file => options[:file]) + exit +end \ No newline at end of file diff --git a/bin/wheneverize b/bin/wheneverize index 50dbda2..c92d7f9 100644 --- a/bin/wheneverize +++ b/bin/wheneverize @@ -3,6 +3,7 @@ # 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]" @@ -40,6 +41,7 @@ content = <<-FILE # every 2.hours do # command "/usr/bin/some_great_command" # runner "MyModel.some_method" +# rake "some:great:rake:task" # end # # every 4.days do diff --git a/lib/tasks/whenever.rake b/lib/tasks/whenever.rake deleted file mode 100644 index 67c9266..0000000 --- a/lib/tasks/whenever.rake +++ /dev/null @@ -1,21 +0,0 @@ -namespace :whenever do - - desc "outputs cron" - task :output_cron do - puts Whenever.cron(:file => "config/schedule.rb") - end - - desc "writes cron" - task :write_cron do - require 'tempfile' - cron_output = Whenever.cron(:file => "config/schedule.rb") - - tmp_cron_file = Tempfile.new('whenever_tmp_cron').path - File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file| - file << cron_output - end - sh "crontab #{tmp_cron_file}" - puts "[write] crontab file updated" - end - -end \ No newline at end of file diff --git a/lib/version.rb b/lib/version.rb index 9e0357d..d067324 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -2,7 +2,7 @@ module Whenever module VERSION #:nodoc: MAJOR = 0 MINOR = 1 - TINY = 3 + TINY = 4 STRING = [MAJOR, MINOR, TINY].join('.') end diff --git a/lib/whenever.rb b/lib/whenever.rb index ff1fed5..1762c6e 100644 --- a/lib/whenever.rb +++ b/lib/whenever.rb @@ -7,19 +7,13 @@ unless defined?(Whenever) rescue LoadError => e nil end - - # Load Whenever's rake tasks - begin - Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each { |rake| load rake } - rescue LoadError => e - nil - end end - +# Dependencies require 'activesupport' require 'chronic' +# Whenever files require 'base' require 'version' require 'job_list' diff --git a/whenever.gemspec b/whenever.gemspec index 9c5c157..bb9ad9c 100644 --- a/whenever.gemspec +++ b/whenever.gemspec @@ -2,16 +2,16 @@ Gem::Specification.new do |s| s.name = %q{whenever} - s.version = "0.1.3" + s.version = "0.1.4" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= s.authors = ["Javan Makhmali"] - s.date = %q{2009-02-16} + s.date = %q{2009-02-17} s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.} s.email = %q{javan@javan.us} s.executables = ["whenever", "wheneverize"] - s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/tasks/whenever.rake", "lib/version.rb", "lib/whenever.rb", "README.rdoc"] - s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/tasks/whenever.rake", "lib/version.rb", "lib/whenever.rb", "Manifest", "Rakefile", "README.rdoc", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec"] + s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "README.rdoc"] + s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Manifest", "Rakefile", "README.rdoc", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec"] s.has_rdoc = true s.homepage = %q{http://github.com/javan/whenever} s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]