Added more opts to whenever binary. Moved code from rake tasks into bin files themselves and removed rake files. Bumped version to 0.1.4
This commit is contained in:
parent
44d6716f80
commit
469fd369db
@ -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
|
== 0.1.3 / February 16th, 2009
|
||||||
|
|
||||||
* Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
|
* Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
|
||||||
|
@ -14,14 +14,14 @@ In a Rails (2.1 or greater) application:
|
|||||||
in your "config/environment.rb" file:
|
in your "config/environment.rb" file:
|
||||||
|
|
||||||
Rails::Initializer.run do |config|
|
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
|
end
|
||||||
|
|
||||||
To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary).
|
To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary).
|
||||||
|
|
||||||
In older versions of Rails:
|
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
|
$ gem install javan-whenever
|
||||||
|
|
||||||
in your "config/environment.rb" file:
|
in your "config/environment.rb" file:
|
||||||
@ -81,7 +81,7 @@ in your "config/deploy.rb" file do something like:
|
|||||||
namespace :deploy do
|
namespace :deploy do
|
||||||
desc "write the crontab file"
|
desc "write the crontab file"
|
||||||
task :write_crontab, :roles => :app do
|
task :write_crontab, :roles => :app do
|
||||||
run "cd #{release_path} && whenever -c"
|
run "cd #{release_path} && whenever --write-crontab"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
45
bin/whenever
45
bin/whenever
@ -1,17 +1,54 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
require 'rake'
|
require 'rubygems'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
require 'fileutils'
|
||||||
|
require 'tempfile'
|
||||||
require 'whenever'
|
require 'whenever'
|
||||||
|
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../lib/version")
|
require File.expand_path(File.dirname(__FILE__) + "/../lib/version")
|
||||||
|
|
||||||
task = "whenever:output_cron"
|
options = Hash.new
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: whenever [options]"
|
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('-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!
|
end.parse!
|
||||||
|
|
||||||
Rake::Task[task].invoke
|
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
|
@ -3,6 +3,7 @@
|
|||||||
# This file is based heavily on Capistrano's `capify` command
|
# This file is based heavily on Capistrano's `capify` command
|
||||||
|
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: #{File.basename($0)} [path]"
|
opts.banner = "Usage: #{File.basename($0)} [path]"
|
||||||
@ -40,6 +41,7 @@ content = <<-FILE
|
|||||||
# every 2.hours do
|
# every 2.hours do
|
||||||
# command "/usr/bin/some_great_command"
|
# command "/usr/bin/some_great_command"
|
||||||
# runner "MyModel.some_method"
|
# runner "MyModel.some_method"
|
||||||
|
# rake "some:great:rake:task"
|
||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
# every 4.days do
|
# every 4.days do
|
||||||
|
@ -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
|
|
@ -2,7 +2,7 @@ module Whenever
|
|||||||
module VERSION #:nodoc:
|
module VERSION #:nodoc:
|
||||||
MAJOR = 0
|
MAJOR = 0
|
||||||
MINOR = 1
|
MINOR = 1
|
||||||
TINY = 3
|
TINY = 4
|
||||||
|
|
||||||
STRING = [MAJOR, MINOR, TINY].join('.')
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
||||||
end
|
end
|
||||||
|
@ -7,19 +7,13 @@ unless defined?(Whenever)
|
|||||||
rescue LoadError => e
|
rescue LoadError => e
|
||||||
nil
|
nil
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
require 'activesupport'
|
require 'activesupport'
|
||||||
require 'chronic'
|
require 'chronic'
|
||||||
|
|
||||||
|
# Whenever files
|
||||||
require 'base'
|
require 'base'
|
||||||
require 'version'
|
require 'version'
|
||||||
require 'job_list'
|
require 'job_list'
|
||||||
|
@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{whenever}
|
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.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Javan Makhmali"]
|
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.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
|
||||||
s.email = %q{javan@javan.us}
|
s.email = %q{javan@javan.us}
|
||||||
s.executables = ["whenever", "wheneverize"]
|
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.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/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.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.has_rdoc = true
|
||||||
s.homepage = %q{http://github.com/javan/whenever}
|
s.homepage = %q{http://github.com/javan/whenever}
|
||||||
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
|
||||||
|
Loading…
Reference in New Issue
Block a user