-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathconsumable.rb
More file actions
31 lines (25 loc) · 842 Bytes
/
consumable.rb
File metadata and controls
31 lines (25 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# encoding: UTF-8
module CASServer::Model
module Consumable
def consume!
self.consumed = Time.now
self.save!
end
def self.included(mod)
mod.extend(ClassMethods)
end
module ClassMethods
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 = where(conditions).count
$LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.demodulize}"+
"#{'s' if expired_tickets_count > 1}.") if expired_tickets_count > 0
where(conditions).destroy_all
end
end
end
end
end