Skip to content

Instantly share code, notes, and snippets.

View devdatta's full-sized avatar

Devdatta Kane devdatta

View GitHub Profile
#Tasks have been added to fully maintain nginx, unicorn, redis, memcached, start resque workers and run any command on any server in the farm.
#<pre>
#cap nginx:restart # Restart Nginx.
#cap nginx:start # Start Nginx.
#cap nginx:status # Status of Nginx.
#cap nginx:stop # Stop Nginx.
#cap nginx:tail_error # Tail the Nginx error logs.
#cap unicorn:reload # reload your unicorn servers.
#cap unicorn:restart # restart your unicorn servers.
#cap unicorn:start # start your unicorn servers.
module Resque
##
# Resque StateMachine
#
# Is a Mash to be used in a resque queue. The create method will
# initiate the object and enqueue it.
#
# Can pass in a run_at attribute to delay the run.
# Can pass in a test_mode attribute to force test mode.
#
class GetEventResult
@queue = :events
def self.perform(event_id, attempt=0)
event = Event.find(event_id)
Rails.logger.info "Fetching results for event ##{event.id} (#{event.name})..."
begin
results = EventImporter.new(event.datetime.to_date).get_results(event)
rescue OpenURI::HTTPError
ftasks = Resque::Failure.all(0, 1000000)
Resque::Failure.clear()
ftasks.each do |ftask|
queue = ftask["queue"]
payload = ftask["payload"]
Resque::Job.new(queue, payload).recreate()
end