Module: LifeBoat::ActiveRecord

Defined in:
lib/lifeboat.rb

Instance Method Summary collapse

Instance Method Details

#has_lifeboat(options = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/lifeboat.rb', line 101

def has_lifeboat(options={})
  include LifeBoat::Queues

  if options[:format] == :xml
    format = :to_xml
  else
    format = :to_json
  end

  [:create, :update, :destroy ].each do |action|
    define_method(action.to_s + "_lifeboat") do
      begin
        return unless (RAILS_ENV == "production") or (RAILS_ENV == "testing")
        @cue = RightAws::SqsGen2.new(Credentials.key, Credentials.secret)
        queue_name = action.to_s+"_"+ self.class.to_s.downcase + "_" + RAILS_ENV
        q = RightAws::SqsGen2::Queue.create(@cue, queue_name, true, 1000)
        q.send_message(self.attributes.send format)
      rescue RightAws::AwsError => error
        puts error
      end
    end
  end
end