retry-handler 0.0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Changes +8 -0
- data/Gemfile +4 -0
- data/LICENSE +3 -1
- data/README.rdoc +34 -0
- data/Rakefile +2 -51
- data/lib/retry-handler.rb +10 -0
- data/lib/retry-handler/version.rb +5 -0
- data/retry-handler.gemspec +17 -0
- metadata +39 -43
- data/README +0 -3
- data/TODO +0 -4
data/.gitignore
ADDED
data/Changes
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= retry-handler
|
2
|
+
easy retry handling
|
3
|
+
|
4
|
+
== What is this
|
5
|
+
このライブラリは失敗した時にN回リトライするという処理を簡単に記述することが出来るモジュールです。
|
6
|
+
Proc.new{
|
7
|
+
# なんかエラーの起こるコード
|
8
|
+
}.retry(:max => 3, :accept_exception => StandardError)
|
9
|
+
|
10
|
+
とか書いておくとなんかProc内で例外(この場合はStandardErrorなので、ほとんどの例外が対象)が発生した時最大3回まで、
|
11
|
+
Procのコードをリトライしてくれるというのが簡単にかける。
|
12
|
+
|
13
|
+
また:waitというオプションがあり、これ指定するとエラーがあったとき、3秒間waitのあと、次の試行してくれるようになる。
|
14
|
+
retry-handler自体の処理の流れを可視化したいときは:loggerオプションを付加すると良い。
|
15
|
+
lambda{}.retry(:max => 3, :wait => 3)
|
16
|
+
lambda{}.retry(:max => 3, :wait => 3, :logger => Logger.new(STDERR)
|
17
|
+
|
18
|
+
ちなみにProc.newと書くのがダサいときは、lambdaでもbegin-endでも使える
|
19
|
+
lambda{}.retry(:max => 3)
|
20
|
+
|
21
|
+
begin
|
22
|
+
end.retry(:max => 3)
|
23
|
+
|
24
|
+
== Method#retryの使い方
|
25
|
+
たとえばFile.readをretryableにするコード例です
|
26
|
+
File.method(:read).retry("./not_found.txt", :accept_exception => Exception, :logger => Logger.new(STDERR))
|
27
|
+
|
28
|
+
== How to Install
|
29
|
+
Works on Ruby1.8/1.9
|
30
|
+
gem install retry-handler
|
31
|
+
|
32
|
+
== Author
|
33
|
+
lurker(kimoto)
|
34
|
+
|
data/Rakefile
CHANGED
@@ -1,51 +1,2 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'rubygems/specification'
|
4
|
-
require 'date'
|
5
|
-
require 'spec/rake/spectask'
|
6
|
-
|
7
|
-
spec = Gem::Specification.new do |s|
|
8
|
-
s.name = "retry-handler"
|
9
|
-
s.version = "0.0.1"
|
10
|
-
s.author = "Takumi KIMOTO"
|
11
|
-
s.email = "peerler@gmail.com"
|
12
|
-
s.homepage = "http://twitter.com/lurker_"
|
13
|
-
s.description = s.summary = "retry handler"
|
14
|
-
|
15
|
-
s.platform = Gem::Platform::RUBY
|
16
|
-
s.has_rdoc = true
|
17
|
-
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
|
18
|
-
s.summary = "retry handler"
|
19
|
-
|
20
|
-
# Uncomment this to add a dependency
|
21
|
-
# s.add_dependency "foo"
|
22
|
-
|
23
|
-
s.require_path = 'lib'
|
24
|
-
s.autorequire = 'lib/retry-handler.rb'
|
25
|
-
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
|
26
|
-
end
|
27
|
-
|
28
|
-
task :default => :spec
|
29
|
-
|
30
|
-
desc "Run specs"
|
31
|
-
Spec::Rake::SpecTask.new do |t|
|
32
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
33
|
-
t.spec_opts = %w(-fs --color)
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
38
|
-
pkg.gem_spec = spec
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "install the gem locally"
|
42
|
-
task :install => [:package] do
|
43
|
-
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "create a gemspec file"
|
47
|
-
task :make_spec do
|
48
|
-
File.open("#{GEM}.gemspec", "w") do |file|
|
49
|
-
file.puts spec.to_ruby
|
50
|
-
end
|
51
|
-
end
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
data/lib/retry-handler.rb
CHANGED
@@ -54,8 +54,18 @@ class Proc
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
class Method
|
58
|
+
def retry(*args)
|
59
|
+
options = args.last.is_a?(::Hash) ? args.pop : {}
|
60
|
+
RetryHandler.retry_handler(options) do
|
61
|
+
self.call(*args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
57
66
|
module Kernel
|
58
67
|
def retry_handler(options={}, &block)
|
59
68
|
block.retry(options) if block_given?
|
60
69
|
end
|
61
70
|
end
|
71
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/retry-handler/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["kimoto"]
|
6
|
+
gem.email = ["sub+peerler@gmail.com"]
|
7
|
+
gem.description = %q{Easy retry handling}
|
8
|
+
gem.summary = %q{Easy retry handling}
|
9
|
+
gem.homepage = "https://github.com/kimoto/retry-handler"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "retry-handler"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Retry::Handler::VERSION
|
17
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: retry-handler
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
authors:
|
8
|
+
- kimoto
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
|
12
|
-
date: 2009-07-13 00:00:00 +09:00
|
13
|
-
default_executable:
|
12
|
+
date: 2012-07-30 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
description: Easy retry handling
|
15
|
+
email:
|
16
|
+
- sub+peerler@gmail.com
|
18
17
|
executables: []
|
19
|
-
|
20
18
|
extensions: []
|
21
|
-
|
22
|
-
|
23
|
-
-
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Changes
|
23
|
+
- Gemfile
|
24
24
|
- LICENSE
|
25
|
-
-
|
26
|
-
files:
|
27
|
-
- LICENSE
|
28
|
-
- README
|
25
|
+
- README.rdoc
|
29
26
|
- Rakefile
|
30
|
-
- TODO
|
31
27
|
- lib/retry-handler.rb
|
28
|
+
- lib/retry-handler/version.rb
|
29
|
+
- retry-handler.gemspec
|
32
30
|
- spec/retry-handler_spec.rb
|
33
31
|
- spec/spec_helper.rb
|
34
|
-
|
35
|
-
homepage: http://twitter.com/lurker_
|
32
|
+
homepage: https://github.com/kimoto/retry-handler
|
36
33
|
licenses: []
|
37
|
-
|
38
34
|
post_install_message:
|
39
35
|
rdoc_options: []
|
40
|
-
|
41
|
-
require_paths:
|
36
|
+
require_paths:
|
42
37
|
- lib
|
43
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
55
50
|
requirements: []
|
56
|
-
|
57
51
|
rubyforge_project:
|
58
|
-
rubygems_version: 1.
|
52
|
+
rubygems_version: 1.8.24
|
59
53
|
signing_key:
|
60
54
|
specification_version: 3
|
61
|
-
summary: retry
|
62
|
-
test_files:
|
63
|
-
|
55
|
+
summary: Easy retry handling
|
56
|
+
test_files:
|
57
|
+
- spec/retry-handler_spec.rb
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
has_rdoc:
|
data/README
DELETED