Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
better retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Maxwell committed Nov 2, 2010
1 parent ab92d55 commit c9b1d4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
25 changes: 23 additions & 2 deletions lib/gizzard/commands.rb
Expand Up @@ -41,16 +41,37 @@ def output(string)
end
end
end

class RetryProxy
def initialize(retries, object)
@inner = object
@retries_left = retries
end

def method_missing(*args)
@inner.send(*args)
rescue
if @retries_left > 0
@retries_left -= 1
STDERR.puts "Retrying..."
method_missing(*args)
else
raise
end
end
end

class ShardCommand < Command
def self.make_service(global_options, log)
Gizzard::Thrift::ShardManager.new(global_options.host, global_options.port, log, global_options.dry)
RetryProxy.new global_options.retry.to_i,
Gizzard::Thrift::ShardManager.new(global_options.host, global_options.port, log, global_options.dry)
end
end

class JobCommand < Command
def self.make_service(global_options, log)
Gizzard::Thrift::JobManager.new(global_options.host, global_options.port + 2, log, global_options.dry)
RetryProxy.new global_options.retry.to_i ,
Gizzard::Thrift::JobManager.new(global_options.host, global_options.port + 2, log, global_options.dry)
end
end

Expand Down
18 changes: 3 additions & 15 deletions lib/gizzmo.rb
Expand Up @@ -370,21 +370,9 @@ def custom_timeout(seconds)
end
end

tries_left = global_options.retry.to_i + 1
begin
while (tries_left -= 1) >= 0
begin
custom_timeout(global_options.timeout) do
Gizzard::Command.run(subcommand_name, global_options, argv, subcommand_options, log)
end
break
rescue
if tries_left > 0
STDERR.puts "Retrying..."
else
raise
end
end
begin
custom_timeout(global_options.timeout) do
Gizzard::Command.run(subcommand_name, global_options, argv, subcommand_options, log)
end
rescue HelpNeededError => e
if e.class.name != e.message
Expand Down

0 comments on commit c9b1d4e

Please sign in to comment.