cron_wrapper 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # A sample Gemfile
2
+ source "http://rubygems.org"
3
+
4
+ group :development, :test do
5
+ gem 'echoe'
6
+ gem "rspec"
7
+ end
@@ -0,0 +1,34 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ allison (2.0.3)
5
+ diff-lcs (1.1.3)
6
+ echoe (4.6.3)
7
+ allison (>= 2.0.3)
8
+ gemcutter (>= 0.7.0)
9
+ rake (>= 0.9.2)
10
+ rdoc (>= 3.6.1)
11
+ rubyforge (>= 2.0.4)
12
+ gemcutter (0.7.0)
13
+ json (1.6.1)
14
+ json_pure (1.6.1)
15
+ rake (0.9.2.2)
16
+ rdoc (3.11)
17
+ json (~> 1.4)
18
+ rspec (2.7.0)
19
+ rspec-core (~> 2.7.0)
20
+ rspec-expectations (~> 2.7.0)
21
+ rspec-mocks (~> 2.7.0)
22
+ rspec-core (2.7.1)
23
+ rspec-expectations (2.7.0)
24
+ diff-lcs (~> 1.1.2)
25
+ rspec-mocks (2.7.0)
26
+ rubyforge (2.0.4)
27
+ json_pure (>= 1.1.7)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ echoe
34
+ rspec
data/Manifest CHANGED
@@ -1,7 +1,9 @@
1
+ Gemfile
2
+ Gemfile.lock
1
3
  Manifest
2
4
  Rakefile
3
5
  bin/cron_wrapper
4
- cron_wrapper.gemspec
6
+ lib/cron/awesome_script.rb
5
7
  lib/cron_wrapper.rb
6
8
  spec/cron_wrapper_spec.rb
7
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.11') do |p|
5
+ Echoe.new('cron_wrapper', '0.0.12') do |p|
6
6
  p.description = "A gem that provides useful features for running ruby or Rails scripts with cron"
7
- p.url = "http://rubyisbeautiful.com"
7
+ p.url = "http://github.com/rubyisbeautiful"
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"
@@ -2,28 +2,26 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cron_wrapper}
5
- s.version = "0.0.11"
5
+ s.version = "0.0.12"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Bryan Taylor"]
9
- s.cert_chain = ["/home/bryan/gem_private_key/gem-public_cert.pem"]
10
- s.date = %q{2011-03-03}
11
- s.default_executable = %q{cron_wrapper}
8
+ s.authors = [%q{Bryan Taylor}]
9
+ s.cert_chain = [%q{/Users/bryan/.gem_credentials/gem-public_cert.pem}]
10
+ s.date = %q{2012-03-26}
12
11
  s.description = %q{A gem that provides useful features for running ruby or Rails scripts with cron}
13
12
  s.email = %q{btaylor39 @nospam@ csc.com}
14
- s.executables = ["cron_wrapper"]
15
- s.extra_rdoc_files = ["bin/cron_wrapper", "lib/cron_wrapper.rb"]
16
- s.files = ["Manifest", "Rakefile", "bin/cron_wrapper", "cron_wrapper.gemspec", "lib/cron_wrapper.rb", "spec/cron_wrapper_spec.rb", "spec/spec_helper.rb"]
17
- s.homepage = %q{http://rubyisbeautiful.com}
18
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Cron_wrapper"]
19
- s.require_paths = ["lib"]
13
+ s.executables = [%q{cron_wrapper}]
14
+ s.extra_rdoc_files = [%q{bin/cron_wrapper}, %q{lib/cron/awesome_script.rb}, %q{lib/cron_wrapper.rb}]
15
+ s.files = [%q{Gemfile}, %q{Gemfile.lock}, %q{Manifest}, %q{Rakefile}, %q{bin/cron_wrapper}, %q{lib/cron/awesome_script.rb}, %q{lib/cron_wrapper.rb}, %q{spec/cron_wrapper_spec.rb}, %q{spec/spec_helper.rb}, %q{cron_wrapper.gemspec}]
16
+ s.homepage = %q{http://github.com/rubyisbeautiful}
17
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Cron_wrapper}]
18
+ s.require_paths = [%q{lib}]
20
19
  s.rubyforge_project = %q{cron_wrapper}
21
- s.rubygems_version = %q{1.3.7}
22
- s.signing_key = %q{/home/bryan/gem_private_key/gem-private_key.pem}
20
+ s.rubygems_version = %q{1.8.6}
21
+ s.signing_key = %q{/Users/bryan/.gem_credentials/gem-private_key.pem}
23
22
  s.summary = %q{features: locking to prevent resource contention, standard logging, optional rails integration}
24
23
 
25
24
  if s.respond_to? :specification_version then
26
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
27
25
  s.specification_version = 3
28
26
 
29
27
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -0,0 +1 @@
1
+ sleep(2); puts "awesome"
@@ -13,6 +13,7 @@ class CronWrapper
13
13
  @options[:root] = '.'
14
14
  @options[:lock_dir] = nil
15
15
  @options[:dry_run] = false
16
+ @options[:name] = nil
16
17
  @options[:silent] = false
17
18
  @options[:verbose] = false
18
19
  @options[:log] = nil
@@ -35,6 +36,7 @@ class CronWrapper
35
36
 
36
37
  opts.on("--wrap FILE", "file to run") { |o| @options[:target] = o }
37
38
  opts.on("--wrap-dry-run", "dry run (default: off)") { |o| @options[:dry_run] = o }
39
+ opts.on("--wrap-name NAME", "use NAME for the lock file (default: same as wrap script)") { |o| @options[:name] = o }
38
40
  opts.on("--wrap-rails", "Try to load Rails (default: off)") { |o| @options[:rails] = o }
39
41
  opts.on("--wrap-root DIR", "Root or working directory (default: .)") { |o| @options[:root] = o }
40
42
  opts.on("--wrap-lock_dir DIR", "Lock dir (default: <root>/tmp/locks)") { |o| @options[:lock_dir] = o }
@@ -105,8 +107,13 @@ class CronWrapper
105
107
 
106
108
  def run
107
109
  base_name = @options[:target]
108
- target = File.join(@options[:root], "lib/cron/#{base_name}.rb")
109
- lock_file = File.join(@options[:lock_dir], "/#{base_name}.lock")
110
+ target = File.join(@options[:root], "lib/cron/#{base_name}.rb")
111
+ if @options[:name]
112
+ lock_file = File.join(@options[:lock_dir], "/#{@options[:name]}.lock")
113
+ else
114
+ lock_file = File.join(@options[:lock_dir], "/#{base_name}.lock")
115
+ end
116
+
110
117
 
111
118
  if File.exists? lock_file
112
119
  stale = false
@@ -118,7 +118,22 @@ describe "cron_wrapper" do
118
118
  @pid = nil
119
119
  remove_lock
120
120
  end
121
-
121
+
122
+
123
+ it "should create the lock file in lock_dir using the --wrap-name if provided" do
124
+ t = Thread.new { `#{cmd} --wrap awesome_script --wrap-name foobar_script --wrap-verbose --wrap-root #{root} --wrap-log log/awesome_script.log` }
125
+ Timeout::timeout(3) do
126
+ begin
127
+ @pid = File.read "#{root}/tmp/locks/foobar_script.lock"
128
+ rescue
129
+ retry
130
+ end
131
+ end.should_not raise_error TimeoutError
132
+
133
+ @pid.nil?.should_not == true
134
+ t.join
135
+ end
136
+
122
137
 
123
138
  it "should create a lock file in lock_dir if no lock file exists" do
124
139
  t = Thread.new { `#{cmd} --wrap awesome_script --wrap-verbose --wrap-root #{root} --wrap-log log/awesome_script.log` }
@@ -159,7 +174,7 @@ describe "cron_wrapper" do
159
174
  end
160
175
 
161
176
 
162
- it "should not execute if the lock file is there and the pid is valid" do
177
+ it "should not execute if the default lock file is there and the pid is valid" do
163
178
  File.open("#{root}/tmp/locks/awesome_script.lock", 'w') do |file|
164
179
  file << Process::pid
165
180
  end
@@ -173,7 +188,7 @@ describe "cron_wrapper" do
173
188
  end
174
189
 
175
190
 
176
- it "should execute if the lock file is there but the pid is invalid" do
191
+ it "should execute if the default lock file is there but the pid is invalid" do
177
192
  File.open("#{root}/tmp/locks/awesome_script.lock", 'w') do |file|
178
193
  file << 'foo'
179
194
  end
@@ -185,6 +200,49 @@ describe "cron_wrapper" do
185
200
 
186
201
  ((end_time - start_time) > 2).should == true
187
202
  end
203
+
204
+
205
+ it "should execute if the lock file is there under a different name" do
206
+ File.open("#{root}/tmp/locks/awesome_script.lock", 'w') do |file|
207
+ file << Process::pid
208
+ end
209
+
210
+ start_time = Time.now
211
+ Process.fork { `#{cmd} --wrap awesome_script --wrap-name foobar_script --wrap-verbose --wrap-root #{root} --wrap-log log/awesome_script.log` }
212
+ Process.wait
213
+ end_time = Time.now
214
+
215
+ ((end_time - start_time) > 2).should == true
216
+ end
217
+
218
+
219
+ it "should not execute if the custom lock file is there and the pid is valid" do
220
+ File.open("#{root}/tmp/locks/foobar_script.lock", 'w') do |file|
221
+ file << Process::pid
222
+ end
223
+
224
+ start_time = Time.now
225
+ Process.fork { `#{cmd} --wrap awesome_script --wrap-name foobar_script --wrap-verbose --wrap-root #{root} --wrap-log log/awesome_script.log` }
226
+ Process.wait
227
+ end_time = Time.now
228
+
229
+ ((end_time - start_time) < 1).should == true
230
+ end
231
+
232
+
233
+ it "should execute if the custom lock file is there but the pid is invalid" do
234
+ File.open("#{root}/tmp/locks/foobar_script.lock", 'w') do |file|
235
+ file << 'foo'
236
+ end
237
+
238
+ start_time = Time.now
239
+ Process.fork { `#{cmd} --wrap awesome_script --wrap-name foobar_script --wrap-verbose --wrap-root #{root} --wrap-log log/awesome_script.log` }
240
+ Process.wait
241
+ end_time = Time.now
242
+
243
+ ((end_time - start_time) > 2).should == true
244
+ end
245
+
188
246
  end
189
247
 
190
248
 
@@ -1,2 +1 @@
1
1
  require 'rspec/core'
2
- require 'autotest/rspec2'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cron_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
5
- prerelease: false
4
+ hash: 7
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 11
10
- version: 0.0.11
9
+ - 12
10
+ version: 0.0.12
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bryan Taylor
@@ -36,8 +36,7 @@ cert_chain:
36
36
  NK5lPw==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-03-03 00:00:00 +00:00
40
- default_executable:
39
+ date: 2012-03-26 00:00:00 Z
41
40
  dependencies: []
42
41
 
43
42
  description: A gem that provides useful features for running ruby or Rails scripts with cron
@@ -48,17 +47,20 @@ extensions: []
48
47
 
49
48
  extra_rdoc_files:
50
49
  - bin/cron_wrapper
50
+ - lib/cron/awesome_script.rb
51
51
  - lib/cron_wrapper.rb
52
52
  files:
53
+ - Gemfile
54
+ - Gemfile.lock
53
55
  - Manifest
54
56
  - Rakefile
55
57
  - bin/cron_wrapper
56
- - cron_wrapper.gemspec
58
+ - lib/cron/awesome_script.rb
57
59
  - lib/cron_wrapper.rb
58
60
  - spec/cron_wrapper_spec.rb
59
61
  - spec/spec_helper.rb
60
- has_rdoc: true
61
- homepage: http://rubyisbeautiful.com
62
+ - cron_wrapper.gemspec
63
+ homepage: http://github.com/rubyisbeautiful
62
64
  licenses: []
63
65
 
64
66
  post_install_message:
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  requirements: []
92
94
 
93
95
  rubyforge_project: cron_wrapper
94
- rubygems_version: 1.3.7
96
+ rubygems_version: 1.8.6
95
97
  signing_key:
96
98
  specification_version: 3
97
99
  summary: "features: locking to prevent resource contention, standard logging, optional rails integration"
metadata.gz.sig CHANGED
Binary file