cron_wrapper 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Manifest CHANGED
@@ -1,4 +1,9 @@
1
1
  Manifest
2
2
  Rakefile
3
3
  bin/cron_wrapper
4
+ cron_wrapper.gemspec
5
+ lib/cron/awesome_script.rb
4
6
  lib/cron_wrapper.rb
7
+ spec/cron_wrapper_spec.rb
8
+ spec/ruby_forker.rb
9
+ spec/spec_helper.rb
data/Rakefile CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('cron_wrapper', '0.0.2') do |p|
5
+ Echoe.new('cron_wrapper', '0.0.3') do |p|
6
6
  p.description = "A gem that provides useful features for running ruby or Rails scripts with cron"
7
- p.url = "http://bugzilla.visaops.net/project_automate_groups/trunk/projects/cron_wrapper"
7
+ p.url = "http://rubyisbeautiful.com"
8
8
  p.author = "Bryan Taylor"
9
9
  p.summary = 'features: locking to prevent resource contention, standard logging, optional rails integration'
10
10
  p.email = "btaylor39 @nospam@ csc.com"
data/bin/cron_wrapper CHANGED
@@ -1,4 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'cron_wrapper'
3
+ begin
4
+ require 'cron_wrapper'
5
+ rescue LoadError
6
+ require 'lib/cron_wrapper.rb'
7
+ end
4
8
  CronWrapper.new(ARGV).run
data/cron_wrapper.gemspec CHANGED
@@ -2,22 +2,24 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cron_wrapper}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Taylor"]
9
- s.date = %q{2011-02-18}
9
+ s.cert_chain = ["/Users/bryan/.gem/gem-public_cert.pem"]
10
+ s.date = %q{2011-02-22}
10
11
  s.default_executable = %q{cron_wrapper}
11
12
  s.description = %q{A gem that provides useful features for running ruby or Rails scripts with cron}
12
13
  s.email = %q{btaylor39 @nospam@ csc.com}
13
14
  s.executables = ["cron_wrapper"]
14
- s.extra_rdoc_files = ["bin/cron_wrapper", "lib/cron_wrapper.rb"]
15
- s.files = ["Manifest", "Rakefile", "bin/cron_wrapper", "lib/cron_wrapper.rb", "cron_wrapper.gemspec"]
16
- s.homepage = %q{http://bugzilla.visaops.net/project_automate_groups/trunk/projects/cron_wrapper}
15
+ s.extra_rdoc_files = ["bin/cron_wrapper", "lib/cron/awesome_script.rb", "lib/cron_wrapper.rb"]
16
+ s.files = ["Manifest", "Rakefile", "bin/cron_wrapper", "cron_wrapper.gemspec", "lib/cron/awesome_script.rb", "lib/cron_wrapper.rb", "spec/cron_wrapper_spec.rb", "spec/ruby_forker.rb", "spec/spec_helper.rb"]
17
+ s.homepage = %q{http://rubyisbeautiful.com}
17
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cron_wrapper"]
18
19
  s.require_paths = ["lib"]
19
20
  s.rubyforge_project = %q{cron_wrapper}
20
21
  s.rubygems_version = %q{1.3.7}
22
+ s.signing_key = %q{/Users/bryan/.gem/gem-private_key.pem}
21
23
  s.summary = %q{features: locking to prevent resource contention, standard logging, optional rails integration}
22
24
 
23
25
  if s.respond_to? :specification_version then
@@ -0,0 +1,2 @@
1
+ sleep(1)
2
+ puts "awesome"
data/lib/cron_wrapper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'optparse'
2
2
  require 'logger'
3
+ require 'fileutils'
3
4
 
4
5
  class CronWrapper
5
6
 
@@ -100,7 +101,7 @@ class CronWrapper
100
101
 
101
102
 
102
103
 
103
- def run
104
+ def run
104
105
  base_name = ARGV[0]
105
106
  target = File.join(@options[:root], "lib/cron/#{base_name}.rb")
106
107
  lock_file = File.join(@options[:lock_dir], "/#{base_name}.lock")
@@ -115,7 +116,7 @@ class CronWrapper
115
116
  logger.debug "cleaning stale pid #{lock_pid} from #{lock_file}"
116
117
  end
117
118
  end
118
-
119
+
119
120
  File.open(lock_file, 'w') do |file|
120
121
  file << Process::pid
121
122
  end
@@ -134,7 +135,13 @@ class CronWrapper
134
135
  logger.debug e.backtrace
135
136
  end
136
137
 
137
- FileUtils.rm_f lock_file rescue nil
138
+ begin
139
+ FileUtils.rm_f lock_file
140
+ rescue => e
141
+ logger.fatal "couldn't remove lock file: #{lock_file}"
142
+ logger.info e.message
143
+ logger.debug e.backtrace
144
+ end
138
145
 
139
146
  end
140
147
 
@@ -0,0 +1,55 @@
1
+ require 'fileutils'
2
+ require 'timeout'
3
+ root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
4
+ cmd = File.join root, 'bin/cron_wrapper'
5
+
6
+ def remove_lock
7
+ FileUtils.rm_f "tmp/locks/awesome_script.lock" rescue nil
8
+ end
9
+
10
+
11
+ describe "cron_wrapper" do
12
+
13
+ before(:each) do
14
+ @pid = nil
15
+ remove_lock
16
+ end
17
+
18
+
19
+ it "should create a lock file in lock_dir if no lock file exists" do
20
+ t = Thread.new { `#{cmd} awesome_script --wrap-verbose --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log` }
21
+ Timeout::timeout(2) do
22
+ begin
23
+ @pid = File.read "#{root}/tmp/locks/awesome_script.lock"
24
+ rescue
25
+ retry
26
+ end
27
+ end.should_not raise_error TimeoutError
28
+
29
+ @pid.nil?.should_not == true
30
+ t.join
31
+ end
32
+
33
+
34
+ it "should remove the lock file in lock_dir after execution" do
35
+ `#{cmd} awesome_script --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log`
36
+ File.exists?("tmp/locks/awesome_script.lock").should == false
37
+ end
38
+
39
+
40
+ it "should have the pid of the currently executing thread in the lock file" do
41
+ read_pid = nil
42
+ @pid = Process.fork { `#{cmd} awesome_script --wrap-verbose --wrap-skip-rails --wrap-root #{root} --wrap-log log/awesome_script.log` }
43
+
44
+ begin
45
+ read_pid = File.read "#{root}/tmp/locks/awesome_script.lock"
46
+ rescue
47
+ retry
48
+ end
49
+
50
+ Process.wait
51
+ read_pid.should == (@pid + 1).to_s
52
+ end
53
+
54
+
55
+ end
@@ -0,0 +1,13 @@
1
+ require 'rbconfig'
2
+
3
+ module RubyForker
4
+ # Forks a ruby interpreter with same type as ourself.
5
+ # jruby will fork jruby, ruby will fork ruby etc.
6
+ def ruby(args, stderr=nil)
7
+ config = ::RbConfig::CONFIG
8
+ interpreter = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
9
+ cmd = "#{interpreter} #{args}"
10
+ cmd << " 2> #{stderr}" unless stderr.nil?
11
+ `#{cmd}`
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ require 'rspec/core'
2
+ require 'autotest/rspec2'
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,21 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cron_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bryan Taylor
14
14
  autorequire:
15
15
  bindir: bin
16
- cert_chain: []
16
+ cert_chain:
17
+ - |
18
+ -----BEGIN CERTIFICATE-----
19
+ MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MRIwEAYDVQQDDAlidGF5
20
+ bG9yMzkxEzARBgoJkiaJk/IsZAEZFgNjc2MxEzARBgoJkiaJk/IsZAEZFgNjb20w
21
+ HhcNMTEwMjE2MTI1MzQzWhcNMTIwMjE2MTI1MzQzWjA+MRIwEAYDVQQDDAlidGF5
22
+ bG9yMzkxEzARBgoJkiaJk/IsZAEZFgNjc2MxEzARBgoJkiaJk/IsZAEZFgNjb20w
23
+ ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDid0W3CiAzCKP+H70D/FFq
24
+ RnwfMdTqsIGK6pKZVHIqqcZxntJw1r3zHwvDwwjh67/iysB0mum6Palizm0xtBqZ
25
+ wTHO+GXNsTz/+zfihkJMSVhSY8Y58SNuV5m1CmzdVSyVrTyOlkc6+IpHTlpaCpf4
26
+ r3mGtZbsuEpLvU/A3iC778k8Bm9hoKhI/3CoMWQjSTHYfrMDWetuGhu8NbdGK3BN
27
+ E1dgEBdQLAjf8yeY3pmmUE88cr9EvrFVdx7mnI5lzOwZMuFSgEBw5AsB6+vvlTW3
28
+ i75Q4pJwjeM41i2B1u7T4kskmOogfZl3YAulPXrEaTCKHDEQb/Jp4WtTy2v8m+79
29
+ AgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBS36r/0
30
+ ouuKO1EVrbluXYEBlANxODANBgkqhkiG9w0BAQUFAAOCAQEAgNN7J2bWCZDSQQm8
31
+ 7PfoCViUKWIcWEZB+C05R0JDpFue0lL5s6aAt61rPXL6k5UiLtj8QkGSe0vasC9G
32
+ f8eBWU5l3g/HDvsFZ5cIBWk0saF7xlIZC3E98LF8Vcfl9WFibHCuwApxzzcAQvdU
33
+ ocHFXaTM2tz8iRO5pW+Do3GC7Mjbo2mvAGN0H5f4tZkZ+Ttm25bAPpnHfXaWPxKq
34
+ RL48Oo1H6iw8nmjm8YrQC6UdtW8ogetCkJwwFmK/U5YQQsE0NnUSG5Ii5R32ZdaY
35
+ eMvMROg/ZYJZzMayO+XXWYgXhy2UDEP/hNhNzM3E+XJUilcA4dZ/fdX57vL0Qpvn
36
+ NK5lPw==
37
+ -----END CERTIFICATE-----
17
38
 
18
- date: 2011-02-18 00:00:00 +00:00
39
+ date: 2011-02-22 00:00:00 -05:00
19
40
  default_executable:
20
41
  dependencies: []
21
42
 
@@ -27,15 +48,20 @@ extensions: []
27
48
 
28
49
  extra_rdoc_files:
29
50
  - bin/cron_wrapper
51
+ - lib/cron/awesome_script.rb
30
52
  - lib/cron_wrapper.rb
31
53
  files:
32
54
  - Manifest
33
55
  - Rakefile
34
56
  - bin/cron_wrapper
35
- - lib/cron_wrapper.rb
36
57
  - cron_wrapper.gemspec
58
+ - lib/cron/awesome_script.rb
59
+ - lib/cron_wrapper.rb
60
+ - spec/cron_wrapper_spec.rb
61
+ - spec/ruby_forker.rb
62
+ - spec/spec_helper.rb
37
63
  has_rdoc: true
38
- homepage: http://bugzilla.visaops.net/project_automate_groups/trunk/projects/cron_wrapper
64
+ homepage: http://rubyisbeautiful.com
39
65
  licenses: []
40
66
 
41
67
  post_install_message:
metadata.gz.sig ADDED
Binary file