Module: CASServer::Model::Consumable::ClassMethods

Defined in:
lib/casserver/model.rb

Instance Method Summary collapse

Instance Method Details

#cleanup(max_lifetime, max_unconsumed_lifetime) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/casserver/model.rb', line 17

def cleanup(max_lifetime, max_unconsumed_lifetime)
  transaction do
    conditions = ["created_on < ? OR (consumed IS NULL AND created_on < ?)",
                    Time.now - max_lifetime,
                    Time.now - max_unconsumed_lifetime]
                  
    expired_tickets_count = count(:conditions => conditions)

    $LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.demodulize}"+
      "#{'s' if expired_tickets_count > 1}.") if expired_tickets_count > 0

    destroy_all(conditions)
  end
end