javan-whenever 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.4 / February 17th, 2009
2
+
3
+ * Added --load-file and --user opts to whenever binary. [Javan Makhmali]
4
+
5
+
1
6
  == 0.1.3 / February 16th, 2009
2
7
 
3
8
  * Added 'rake' helper for defining scheduled rake tasks. [Javan Makhmali]
data/README.rdoc CHANGED
@@ -14,14 +14,14 @@ In a Rails (2.1 or greater) application:
14
14
  in your "config/environment.rb" file:
15
15
 
16
16
  Rails::Initializer.run do |config|
17
- config.gem 'javan-whenever', :lib => false, :version => '>= 0.1.3' :source => 'http://gems.github.com'
17
+ config.gem 'javan-whenever', :lib => false, :version => '>= 0.1.4' :source => 'http://gems.github.com'
18
18
  end
19
19
 
20
20
  To install this gem (and all other missing gem dependencies), run rake gems:install (use sudo if necessary).
21
21
 
22
22
  In older versions of Rails:
23
23
 
24
- $ gem sources -a http://gems.github.com
24
+ $ gem sources -a http://gems.github.com (you only need to run this once)
25
25
  $ gem install javan-whenever
26
26
 
27
27
  in your "config/environment.rb" file:
@@ -81,7 +81,7 @@ in your "config/deploy.rb" file do something like:
81
81
  namespace :deploy do
82
82
  desc "write the crontab file"
83
83
  task :write_crontab, :roles => :app do
84
- run "cd #{release_path} && whenever -c"
84
+ run "cd #{release_path} && whenever --write-crontab"
85
85
  end
86
86
  end
87
87
 
data/bin/whenever CHANGED
@@ -1,17 +1,54 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'rake'
3
+ require 'rubygems'
4
4
  require 'optparse'
5
+ require 'fileutils'
6
+ require 'tempfile'
5
7
  require 'whenever'
6
8
 
7
9
  require File.expand_path(File.dirname(__FILE__) + "/../lib/version")
8
10
 
9
- task = "whenever:output_cron"
10
-
11
+ options = Hash.new
12
+
11
13
  OptionParser.new do |opts|
12
14
  opts.banner = "Usage: whenever [options]"
13
- opts.on('-c', '--write-crontab') { task = "whenever:write_cron" }
14
15
  opts.on('-v', '--version') { puts "Whenever v#{Whenever::VERSION::STRING}"; exit }
16
+ opts.on('-w', '--write-crontab') { options[:write] = true }
17
+ opts.on('-f', '--load-file [schedule file]', 'default: config/schedule.rb') do |file|
18
+ options[:file] = file if file
19
+ end
20
+ opts.on('-u', '--user [user]', 'default: current user') do |user|
21
+ options[:user] = user if user
22
+ end
15
23
  end.parse!
16
24
 
17
- Rake::Task[task].invoke
25
+ options[:file] ||= 'config/schedule.rb'
26
+
27
+ unless File.exists?(options[:file])
28
+ warn("[fail] can't find file: #{options[:file]}")
29
+ exit(1)
30
+ end
31
+
32
+ if options[:write]
33
+ cron_output = Whenever.cron(:file => options[:file])
34
+ tmp_cron_file = Tempfile.new('whenever_tmp_cron').path
35
+ File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file|
36
+ file << cron_output
37
+ end
38
+
39
+ command = ['crontab']
40
+ command << "-u #{options[:user]}" if options[:user]
41
+ command << tmp_cron_file
42
+
43
+ if system(command.join(' '))
44
+ puts "[write] crontab file updated"
45
+ exit
46
+ else
47
+ warn "[fail] couldn't write crontab"
48
+ exit(1)
49
+ end
50
+
51
+ else
52
+ puts Whenever.cron(:file => options[:file])
53
+ exit
54
+ end
data/bin/wheneverize CHANGED
@@ -3,6 +3,7 @@
3
3
  # This file is based heavily on Capistrano's `capify` command
4
4
 
5
5
  require 'optparse'
6
+ require 'fileutils'
6
7
 
7
8
  OptionParser.new do |opts|
8
9
  opts.banner = "Usage: #{File.basename($0)} [path]"
@@ -40,6 +41,7 @@ content = <<-FILE
40
41
  # every 2.hours do
41
42
  # command "/usr/bin/some_great_command"
42
43
  # runner "MyModel.some_method"
44
+ # rake "some:great:rake:task"
43
45
  # end
44
46
  #
45
47
  # every 4.days do
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Whenever
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 3
5
+ TINY = 4
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/whenever.rb CHANGED
@@ -7,19 +7,13 @@ unless defined?(Whenever)
7
7
  rescue LoadError => e
8
8
  nil
9
9
  end
10
-
11
- # Load Whenever's rake tasks
12
- begin
13
- Dir[File.join(File.dirname(__FILE__), 'tasks', '*.rake')].each { |rake| load rake }
14
- rescue LoadError => e
15
- nil
16
- end
17
10
  end
18
11
 
19
-
12
+ # Dependencies
20
13
  require 'activesupport'
21
14
  require 'chronic'
22
15
 
16
+ # Whenever files
23
17
  require 'base'
24
18
  require 'version'
25
19
  require 'job_list'
data/whenever.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{whenever}
5
- s.version = "0.1.3"
5
+ s.version = "0.1.4"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Javan Makhmali"]
9
- s.date = %q{2009-02-16}
9
+ s.date = %q{2009-02-17}
10
10
  s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
11
11
  s.email = %q{javan@javan.us}
12
12
  s.executables = ["whenever", "wheneverize"]
13
- 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"]
14
- 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"]
13
+ 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"]
14
+ 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"]
15
15
  s.has_rdoc = true
16
16
  s.homepage = %q{http://github.com/javan/whenever}
17
17
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: javan-whenever
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javan Makhmali
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-16 00:00:00 -08:00
12
+ date: 2009-02-17 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,7 +49,6 @@ extra_rdoc_files:
49
49
  - lib/job_types/rake_task.rb
50
50
  - lib/job_types/runner.rb
51
51
  - lib/outputs/cron.rb
52
- - lib/tasks/whenever.rake
53
52
  - lib/version.rb
54
53
  - lib/whenever.rb
55
54
  - README.rdoc
@@ -63,7 +62,6 @@ files:
63
62
  - lib/job_types/rake_task.rb
64
63
  - lib/job_types/runner.rb
65
64
  - lib/outputs/cron.rb
66
- - lib/tasks/whenever.rake
67
65
  - lib/version.rb
68
66
  - lib/whenever.rb
69
67
  - Manifest
@@ -1,21 +0,0 @@
1
- namespace :whenever do
2
-
3
- desc "outputs cron"
4
- task :output_cron do
5
- puts Whenever.cron(:file => "config/schedule.rb")
6
- end
7
-
8
- desc "writes cron"
9
- task :write_cron do
10
- require 'tempfile'
11
- cron_output = Whenever.cron(:file => "config/schedule.rb")
12
-
13
- tmp_cron_file = Tempfile.new('whenever_tmp_cron').path
14
- File.open(tmp_cron_file, File::WRONLY | File::APPEND) do |file|
15
- file << cron_output
16
- end
17
- sh "crontab #{tmp_cron_file}"
18
- puts "[write] crontab file updated"
19
- end
20
-
21
- end