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 69% rename from lib/resque/client.rb rename to lib/resque/backend.rb index 1bc948b24..0d97f445b 100644 --- a/lib/resque/client.rb +++ b/lib/resque/backend.rb @@ -1,9 +1,9 @@ ## -# 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 -# 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. @@ -11,30 +11,30 @@ # 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. 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/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 75% rename from test/resque/client_test.rb rename to test/resque/backend_test.rb index 9a15aa65c..031a300ab 100644 --- a/test/resque/client_test.rb +++ b/test/resque/backend_test.rb @@ -1,16 +1,17 @@ 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) + backend = Resque::Backend.new(redis, logger) - assert_same client.backend.__id__, redis.__id__ + assert_same backend.store.__id__, redis.__id__ end 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