retry-handler 0.0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Changes ADDED
@@ -0,0 +1,8 @@
1
+ v0.2
2
+ Added Method#retry
3
+ example:
4
+ File.method(:read).retry("./not_found.txt", :accept_exception => StandardError, :logger => Logger.new(STDERR))
5
+
6
+ v0.1 (= v0.01)
7
+ First Release
8
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in retry-handler.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 YOUR NAME
1
+ Copyright (c) 2012 kimoto
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -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
- require 'rubygems' unless ENV['NO_RUBYGEMS']
2
- require 'rake/gempackagetask'
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"
@@ -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,5 @@
1
+ module Retry
2
+ module Handler
3
+ VERSION = "0.2"
4
+ end
5
+ end
@@ -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.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
- - Takumi KIMOTO
8
- autorequire: lib/retry-handler.rb
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
- description: retry handler
17
- email: peerler@gmail.com
14
+ description: Easy retry handling
15
+ email:
16
+ - sub+peerler@gmail.com
18
17
  executables: []
19
-
20
18
  extensions: []
21
-
22
- extra_rdoc_files:
23
- - README
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Changes
23
+ - Gemfile
24
24
  - LICENSE
25
- - TODO
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
- has_rdoc: true
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
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
48
- version:
49
- required_rubygems_version: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: "0"
54
- version:
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.3.4
52
+ rubygems_version: 1.8.24
59
53
  signing_key:
60
54
  specification_version: 3
61
- summary: retry handler
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
@@ -1,3 +0,0 @@
1
- == retry-handler
2
-
3
- A gem that provides...
data/TODO DELETED
@@ -1,4 +0,0 @@
1
- TODO:
2
- Fix LICENSE with your name
3
- Fix Rakefile with your name and contact info
4
- Add your code to lib/<%= name %>.rb