cromwell 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +35 -0
- data/VERSION +1 -1
- data/cromwell.gemspec +6 -4
- data/examples/example1.rb +3 -1
- data/examples/example2.rb +3 -1
- data/examples/example3.rb +3 -1
- data/examples/example4.rb +15 -0
- data/lib/cromwell.rb +9 -0
- data/test/test_cromwell.rb +9 -1
- metadata +4 -2
data/README.rdoc
CHANGED
@@ -12,6 +12,16 @@ For a full signal list supported on your operating system, run <code>Signal.list
|
|
12
12
|
|
13
13
|
This gem is based on real-life production code. It is especially useful for protecting various daemon-like scripts in Rails application that are (might be) restarted with every deploy.
|
14
14
|
|
15
|
+
== Installation procedure
|
16
|
+
|
17
|
+
Thanks to {Gemcutter}[http://gemcutter.org/gems/cromwell], installation is as simple as:
|
18
|
+
|
19
|
+
sudo gem install cromwell
|
20
|
+
|
21
|
+
If you plan on changing anything, you should run tests and tests require two additional gems: shoulda and mocha. Install them with:
|
22
|
+
|
23
|
+
sudo gem install thoughtbot-shoulda mocha
|
24
|
+
|
15
25
|
== Usage examples
|
16
26
|
|
17
27
|
The most important in Cromwell API is the <code>protect</code> method. It can be called in two ways: with a block and without a block.
|
@@ -109,6 +119,31 @@ You can inspect Cromwell's state with two methods:
|
|
109
119
|
* <code>Cromwell.protected?</code> returns <code>true</code> when your code is protected, <code>false</code> otherwise.
|
110
120
|
* <code>Cromwell.should_exit?</code> returns <code>true</code> when a signal was caught and termination will ocur after the protected code is over.
|
111
121
|
|
122
|
+
=== Preventing termination
|
123
|
+
|
124
|
+
Since version 0.1.2, you can prevent termination of your script even when a signal was caught. To do so, use <code>Cromwell.should_exit = false</code> like that:
|
125
|
+
|
126
|
+
puts 'You can try to kill me but I will survive!'
|
127
|
+
Cromwell.protect {
|
128
|
+
begin
|
129
|
+
sleep 10
|
130
|
+
ensure
|
131
|
+
puts "Oh noes! You wanted to kill me! But I'll continue my work!" if Cromwell.should_exit?
|
132
|
+
Cromwell.should_exit = false
|
133
|
+
end
|
134
|
+
}
|
135
|
+
puts "You're still here?"
|
136
|
+
|
137
|
+
This script will continue working even after <code>^C</code>:
|
138
|
+
|
139
|
+
$ ruby examples/example4.rb
|
140
|
+
You can try to kill me but I will survive!
|
141
|
+
^C^C^C
|
142
|
+
[ ten seconds pass... ]
|
143
|
+
Oh noes! You wanted to kill me! But I'll continue my work!
|
144
|
+
You're still here?
|
145
|
+
$
|
146
|
+
|
112
147
|
== Compatibility
|
113
148
|
|
114
149
|
Works for me. Tested on Mac OS X 10.4--10.6 and a little bit on Debian Linux. If it works for you too, I'd be glad to know. Cromwell's reliability depends heavily on your operating system's signals implementation reliability (which may not be very stable on some systems).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/cromwell.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cromwell}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Przemyslaw Kowalczyk"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-07}
|
13
13
|
s.description = %q{A very simple wrapper over Signal#trap method that allows you to easily protect your scripts from being killed while they are doing something that should not be interrupted (e.g. interacting with some non-transactional service) or is too costly to restart (e.g. long computations). }
|
14
14
|
s.email = %q{szeryf@negativeiq.pl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"examples/example1.rb",
|
28
28
|
"examples/example2.rb",
|
29
29
|
"examples/example3.rb",
|
30
|
+
"examples/example4.rb",
|
30
31
|
"lib/cromwell.rb",
|
31
32
|
"test/helper.rb",
|
32
33
|
"test/test_cromwell.rb"
|
@@ -41,7 +42,8 @@ Gem::Specification.new do |s|
|
|
41
42
|
"test/test_cromwell.rb",
|
42
43
|
"examples/example1.rb",
|
43
44
|
"examples/example2.rb",
|
44
|
-
"examples/example3.rb"
|
45
|
+
"examples/example3.rb",
|
46
|
+
"examples/example4.rb"
|
45
47
|
]
|
46
48
|
|
47
49
|
if s.respond_to? :specification_version then
|
data/examples/example1.rb
CHANGED
data/examples/example2.rb
CHANGED
data/examples/example3.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# ensure that we use ../lib/cromwell.rb, not the installed gem
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
4
|
require 'cromwell'
|
3
5
|
|
4
6
|
puts "You can't stop me with ^C but you can kill me. My pid is #{$$}."
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# ensure that we use ../lib/cromwell.rb, not the installed gem
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
require 'cromwell'
|
5
|
+
|
6
|
+
puts 'You can try to kill me but I will survive!'
|
7
|
+
Cromwell.protect {
|
8
|
+
begin
|
9
|
+
sleep 10
|
10
|
+
ensure
|
11
|
+
puts "Oh noes! You wanted to kill me! But I'll continue my work!" if Cromwell.should_exit?
|
12
|
+
Cromwell.should_exit = false
|
13
|
+
end
|
14
|
+
}
|
15
|
+
puts "You're still here?"
|
data/lib/cromwell.rb
CHANGED
@@ -46,6 +46,15 @@ class Cromwell
|
|
46
46
|
@@should_exit
|
47
47
|
end
|
48
48
|
|
49
|
+
# call-seq:
|
50
|
+
# Cromwell.should_exit = bool
|
51
|
+
#
|
52
|
+
# Set to false to prevent script from termination even if a signal was caught. You can also set
|
53
|
+
# this to true to have your script terminated after protected block should you wish so.
|
54
|
+
def should_exit= b
|
55
|
+
@@should_exit = b
|
56
|
+
end
|
57
|
+
|
49
58
|
# call-seq:
|
50
59
|
# Cromwell.protected?
|
51
60
|
#
|
data/test/test_cromwell.rb
CHANGED
@@ -132,10 +132,18 @@ class TestCromwell < Test::Unit::TestCase
|
|
132
132
|
end
|
133
133
|
|
134
134
|
should "terminate if should_exit is true" do
|
135
|
-
Cromwell.
|
135
|
+
Cromwell.should_exit = true
|
136
136
|
Cromwell.expects(:exit)
|
137
137
|
Cromwell.unprotect
|
138
138
|
end
|
139
139
|
end # method unprotect
|
140
140
|
|
141
|
+
context "should_exit=" do
|
142
|
+
should "prevent script from terminating if set to false" do
|
143
|
+
Cromwell.should_exit = false
|
144
|
+
Cromwell.expects(:exit).never
|
145
|
+
Cromwell.unprotect
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
141
149
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cromwell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Przemyslaw Kowalczyk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-07 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- examples/example1.rb
|
53
53
|
- examples/example2.rb
|
54
54
|
- examples/example3.rb
|
55
|
+
- examples/example4.rb
|
55
56
|
- lib/cromwell.rb
|
56
57
|
- test/helper.rb
|
57
58
|
- test/test_cromwell.rb
|
@@ -89,3 +90,4 @@ test_files:
|
|
89
90
|
- examples/example1.rb
|
90
91
|
- examples/example2.rb
|
91
92
|
- examples/example3.rb
|
93
|
+
- examples/example4.rb
|