title: How to kick off pubsub subscriber in Rails app
body: <p>I have a Rails (web) app that I need to add a (redis) pub/sub subscriber too. </p>
  
  <p>Below is my PubsubSubscriber class which I need to kick off then the app starts up.</p>
  
  <p>The redis connection is created in a resque.rb initializer file. I tried PubsubSubscriber.new after the connection, but when I try to start the rails server it hangs at:</p>
  
  <pre><code>=&gt; Booting Thin
  =&gt; Rails 3.2.13 application starting in development on http://0.0.0.0:5000
  =&gt; Call with -d to detach
  =&gt; Ctrl-C to shutdown server
  </code></pre>
  
  <p>As opposed to when the server starts successfully:</p>
  
  <pre><code>=&gt; Booting Thin
  =&gt; Rails 3.2.13 application starting in development on http://0.0.0.0:5000
  =&gt; Call with -d to detach
  =&gt; Ctrl-C to shutdown server
  &gt;&gt; Thin web server (v1.5.1 codename Straight Razor)
  &gt;&gt; Maximum connections set to 1024
  &gt;&gt; Listening on 0.0.0.0:5000, CTRL+C to stop
  </code></pre>
  
  <p>Any idea why the server hangs when I try to instantiate the PubsubSubscriber class in the initializer? Is there a better place to start this up?</p>
  
  <hr>
  
  <pre><code># example modified from https://github.com/redis/redis-rb/blob/master/examples/pubsub.rb
  class PubsubSubscriber
  
    def initialize
      $redis.psubscribe( :channel_one ) do |on|
  
        on.psubscribe do |event, total|
        end
  
        on.pmessage do |pattern, event, message|
          # message received, kick off some workers
        end
  
        on.punsubscribe do |event, total|
        end
  
      end
  
   end
  end
  </code></pre>