Skip to content

Instantly share code, notes, and snippets.

@kbaum
kbaum / gist:892247
Created March 29, 2011 12:12
prune_workers_from_terminated_instance.rb
module Resque
def self.unregister_workers_for_host(host)
Resque.workers.select{|worker| worker.id.split(':').first==host}.each(&:unregister_worker)
end
end
Resque.unregister_workers_for_host("ip-10-250-192-51")
gem 'koala'
gem 'resque'
require 'rubygems'
require 'rest-client'
require 'yaml'
config = YAML::load(File.read('/usr/lib/elasticsearch/config/elasticsearch.yml'))
config['discovery']['zen']['ping']['unicast']['hosts'].split(', ').collect{|h| h.sub(':9300', '') }.each do |host|
puts RestClient.get("http://#{host}:9200/_cluster/health").inspect
end
path:
work: /var/lib/elasticsearch/work
logs: /var/log/elasticsearch
data: /var/lib/elasticsearch/data
cluster:
name: mycluster
discovery:
clientSideValidations.callbacks.form.fail = function(form, eventData) {
$.scrollTo('.error', 500, {offset:{left:0,top:-25}} );
};
@kbaum
kbaum / action_mailer_default_url_options.rb
Created November 29, 2011 16:10
Converting absolute email links to relative links
ActionMailer::Base.default_url_options[:host]
when %r{(?:http://www.ourapp.com|^)(/.*)}
$1
if ENV['RUBY_PROF'].present?
require 'ruby-prof'
RubyProf.start
at_exit do
results = RubyProf.stop
File.open "#{Rails.root}/tmp/profile-graph.html", 'w' do |file|
RubyProf::GraphHtmlPrinter.new(results).print(file)
end
module ResqueJob
class CheckMailDelivery
@queue = :medium
def self.perform
gmail = Gmail.connect('stillalive.features', 'ourlittlesecret')
raise "Still Alive mails not being delivered" if gmail.mailbox('[Gmail]/All Mail').emails.last.date.to_time < 30.minutes.ago
end
module ResqueJob
class ActiveSanityJob
@queue = :medium
def self.perform
ActiveSanity::Checker.check!
raise "Invalid Records in your database. Check http://#{ActionMailer::Base.default_url_options[:host]}/admin/invalid_records for more details" if InvalidRecord.any?
end
end
end