From df3b02b8e7eae85e48a5729798d458a2c1396ad3 Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Thu, 18 Apr 2013 09:32:02 -0500 Subject: [PATCH 1/2] Rename Client -> Backend --- lib/resque.rb | 2 +- lib/resque/{client.rb => backend.rb} | 4 ++-- lib/resque/config.rb | 2 +- lib/resque/worker.rb | 4 ++-- test/resque/{client_test.rb => backend_test.rb} | 9 +++++---- 5 files changed, 11 insertions(+), 10 deletions(-) rename lib/resque/{client.rb => backend.rb} (94%) rename test/resque/{client_test.rb => backend_test.rb} (81%) diff --git a/lib/resque.rb b/lib/resque.rb index 5cd9c588b..e9e340052 100644 --- a/lib/resque.rb +++ b/lib/resque.rb @@ -107,7 +107,7 @@ def coder :after_perform= def to_s - "Resque Client connected to #{redis_id}" + "Resque Backend connected to #{redis_id}" end # If 'inline' is true Resque will call #perform method inline diff --git a/lib/resque/client.rb b/lib/resque/backend.rb similarity index 94% rename from lib/resque/client.rb rename to lib/resque/backend.rb index 1bc948b24..a8d0a3271 100644 --- a/lib/resque/client.rb +++ b/lib/resque/backend.rb @@ -1,5 +1,5 @@ ## -# Resque::Client is a wrapper around all things Redis. +# Resque::Backend is a wrapper around all things Redis. # # This provides a level of indirection so that the rest of our code # doesn't need to know anything about Redis, and allows us to someday @@ -11,7 +11,7 @@ # Also, we can theoretically have multiple Redis/Resques going on # one project. module Resque - class Client + class Backend # This error is thrown if we have a problem connecting to # the back end. diff --git a/lib/resque/config.rb b/lib/resque/config.rb index cc7b77cba..af3f1d050 100644 --- a/lib/resque/config.rb +++ b/lib/resque/config.rb @@ -9,7 +9,7 @@ class Config # 2. A 'hostname:port:db' String (to select the Redis db) # 3. A 'hostname:port/namespace' String (to set the Redis namespace) # 4. A Redis URL String 'redis://host:port' - # 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`, + # 5. An instance of `Redis`, `Redis::Backend`, `Redis::DistRedis`, # or `Redis::Namespace`. def redis=(server) return if server == "" or server.nil? diff --git a/lib/resque/worker.rb b/lib/resque/worker.rb index d0ccb11e3..5ca936a14 100644 --- a/lib/resque/worker.rb +++ b/lib/resque/worker.rb @@ -4,7 +4,7 @@ require 'resque/core_ext/hash' require 'resque/worker_registry' require 'resque/errors' -require 'resque/client' +require 'resque/backend' module Resque # A Resque Worker processes jobs. On platforms that support fork(2), @@ -62,7 +62,7 @@ def initialize(queues = [], options = {}) @paused = nil @cant_fork = false - @client = @options.fetch(:client) { Client.new(Resque.redis, Resque.logger) } + @client = @options.fetch(:client) { Backend.new(Resque.redis, Resque.logger) } validate_queues end diff --git a/test/resque/client_test.rb b/test/resque/backend_test.rb similarity index 81% rename from test/resque/client_test.rb rename to test/resque/backend_test.rb index 9a15aa65c..6bafdca08 100644 --- a/test/resque/client_test.rb +++ b/test/resque/backend_test.rb @@ -1,14 +1,15 @@ require 'test_helper' +require 'tempfile' -require 'resque/client' +require 'resque/backend' -describe Resque::Client do +describe Resque::Backend do let(:logger) { Logger.new(Tempfile.new('resque-log')) } describe "#new" do it "needs a Redis to be built" do redis = MiniTest::Mock.new - client = Resque::Client.new(redis, logger) + client = Resque::Backend.new(redis, logger) assert_same client.backend.__id__, redis.__id__ end @@ -30,7 +31,7 @@ def reconnect end end.new - client = Resque::Client.new(redis, logger) + client = Resque::Backend.new(redis, logger) # not actually stubbing right now? Kernel.stub(:sleep, nil) do From d8a80cb259aa6f69bf6cfd11446f8c335db44cca Mon Sep 17 00:00:00 2001 From: Oliver Azevedo Barnes Date: Thu, 18 Apr 2013 09:36:39 -0500 Subject: [PATCH 2/2] Rename Backend#backend to Backend#store, following I18n's naming --- lib/resque/backend.rb | 16 ++++++++-------- test/resque/backend_test.rb | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/resque/backend.rb b/lib/resque/backend.rb index a8d0a3271..0d97f445b 100644 --- a/lib/resque/backend.rb +++ b/lib/resque/backend.rb @@ -3,7 +3,7 @@ # # This provides a level of indirection so that the rest of our code # doesn't need to know anything about Redis, and allows us to someday -# maybe even move away from Redis to another backend if we need to. +# maybe even move away from Redis to another data store if we need to. # # Also helps because we can mock this out in our tests. Only mock # stuff you own. @@ -17,24 +17,24 @@ class Backend # the back end. ConnectionError = Class.new(StandardError) - attr_reader :backend, :logger + attr_reader :store, :logger - def initialize(backend, logger) - @backend = backend + def initialize(store, logger) + @store = store @logger = logger end - # Reconnects to the backend + # Reconnects to the store # - # Maybe your backend died, maybe you've just forked. Whatever the - # reason, this method will attempt to reconnect to the backend. + # Maybe your store died, maybe you've just forked. Whatever the + # reason, this method will attempt to reconnect to the store. # # If it can't connect, it will attempt to rety the connection after # sleeping, and after 3 failures will throw an exception. def reconnect tries = 0 begin - backend.client.reconnect + store.client.reconnect rescue Redis::BaseConnectionError tries += 1 diff --git a/test/resque/backend_test.rb b/test/resque/backend_test.rb index 6bafdca08..031a300ab 100644 --- a/test/resque/backend_test.rb +++ b/test/resque/backend_test.rb @@ -9,9 +9,9 @@ describe "#new" do it "needs a Redis to be built" do redis = MiniTest::Mock.new - client = Resque::Backend.new(redis, logger) + backend = Resque::Backend.new(redis, logger) - assert_same client.backend.__id__, redis.__id__ + assert_same backend.store.__id__, redis.__id__ end end