lib/lifeboat.rb in lifeboat-0.5.0 vs lib/lifeboat.rb in lifeboat-0.6.0

- old
+ new

@@ -13,14 +13,14 @@ end class Credentials def initialize -# TRIED USING THE INITIALIZE FOR THOSE YAML LOADING DOWN THERE -# BUT IT WAS GIVING ME CRAP AND HAD TO DUPLICATE THE LINE -# MY GUEST IS THAT IT IS B/C THEY ARE CLASS METHODS -# TODO: RESEARCH HOW TO REFACTOR OUT + # TRIED USING THE INITIALIZE FOR THOSE YAML LOADING DOWN THERE + # BUT IT WAS GIVING ME CRAP AND HAD TO DUPLICATE THE LINE + # MY GUEST IS THAT IT IS B/C THEY ARE CLASS METHODS + # TODO: RESEARCH HOW TO REFACTOR OUT end begin def self.key AWS.root[RAILS_ENV]['access_key_id'] @@ -32,24 +32,62 @@ puts"LIFEBOAT : AWS Access Key Id needs a subscription for the service." end end +class RescateLifeBoat + + @queue = :lifeboats + + def self.perform(action, klass, id) + record = klass.camelize.constantize.find(id) + record.send(action) + end +end + + module LifeBoat def self.read_queue(name) #TODO EXTRAT OUT THE @CUE INTO HIGHER LEVEL @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret) return @cue.queue(name).receive_messages end + module ResqueCallbacks + def create_resque_lifeboat + if RAILS_ENV == "testing" + self.create_lifeboat + else + Resque.enqueue(RescateLifeBoat, :create_lifeboat ,self.class.name, self.id) + end + end + + def destroy_resque_lifeboat + if RAILS_ENV == "testing" + self.destroy_lifeboat + else + Resque.enqueue(RescateLifeBoat, :destroy_lifeboat, self.class.name, self.id) + end + end + + def update_resque_lifeboat + if RAILS_ENV == "testing" + self.update_lifeboat + else + Resque.enqueue(RescateLifeBoat, :update_lifeboat ,self.class.name, self.id) + end + end + end + + module ActiveRecord + + def has_lifeboat(options={}) include LifeBoat::Queues - - if options[:format] == :xml format = :to_xml else format = :to_json end @@ -72,12 +110,12 @@ module Queues def self.included(base) raise "Object Lacks Proper Callbacks" unless base.respond_to? :after_create base.class_eval do - after_create :create_lifeboat - after_destroy :destroy_lifeboat - after_update :update_lifeboat + after_create :create_resque_lifeboat + after_destroy :destroy_resque_lifeboat + after_update :update_resque_lifeboat end end end end