Avatar Edgar González

  • Random
  • Archive
  • RSS

Resque :: How to clear old workers from Redis

In a Rails 3 application we’re using resque for background jobs. Because we’re running on heroku, with new deploys sometimes appears “phantom” resque workers in resque-web, this “phantom” workers are old workers that running on a previous EC2 instance that currently is terminated, so the phantom workers really don’t exist but the keys are still in Redis.

The way I clean this phantom workers is:

File: ./lib/resque_ext.rb

module ResqueExt
  #
  # ResqueExt.unregister_workers_for_host("ec210-250-192-51")
  #
  def self.unregister_workers_for_host(host)
    Resque.workers.select{|worker| worker.id.split(':').first==host}.each(&:unregister_worker)
  end
end

BTW the ./config/application.rb file includes the ./lib folder to be autoloadable:

config.autoload_paths += %W(#{config.root}/lib)

Based on this gist

    • #rails3
    • #rails
    • #resque
    • #redis
    • #worker
    • #autoload
  • 12 months ago
  • 19
  • Comments
  • Permalink
  • Share
    Tweet

19 Notes/ Hide

  1. mystonyfieldex liked this
  2. christinaert liked this
  3. security980dek liked this
  4. emileeyou89 liked this
  5. gemfury liked this
  6. edgar posted this

Recent comments

Blog comments powered by Disqus
← Previous • Next →

Portrait/Logo

About

When I'm not spending time with Jessica and my kids, I build web applications. Rails developer, believer of Agile Development and Lean startups. NoSQL enthusiast.
CTO and Lord of the API at Piictu

Me, Elsewhere

  • @edgar on Twitter
  • Facebook Profile
  • edgargonzaleznetve on Youtube
  • egg on Flickr
  • edgar on Foursquare
  • My Skype Info
  • Linkedin Profile
  • edgar on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr