Skip to content

Instantly share code, notes, and snippets.

@johnallen3d
Created December 18, 2012 17:49
Show Gist options
  • Save johnallen3d/4330239 to your computer and use it in GitHub Desktop.
Save johnallen3d/4330239 to your computer and use it in GitHub Desktop.
Clean up abandoned Resque workers.

Prune Resque Workers

There is an issue related to running Resque on Heroku and Resque's ability to clean it's state information for workers. This is mostly a cosmetic issue however we got to a point where the Resque Dashboard would timeout because it was trying to display hundreds of workers it thought were sitll running.

This is a heavy handed approach to cleaning up. We are finding any worker that was stared longer than a day ago and manually calling the unregister method. Be advised this will throw DirtyExit errors.

# heroku run console -a appname
days_ago = 1
Resque.workers.select { |w| Date.parse(w.started) < (Date.today - days_ago) }.each { |w| w.unregister_worker }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment