Class: Rubino::Jobs::Handlers::CleanupSessionsJob
- Inherits:
-
Object
- Object
- Rubino::Jobs::Handlers::CleanupSessionsJob
- Defined in:
- lib/rubino/jobs/handlers/cleanup_sessions_job.rb
Overview
Cleans up old ended sessions beyond retention period.
Constant Summary collapse
- RETENTION_DAYS =
30
Instance Method Summary collapse
Instance Method Details
#perform(payload) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rubino/jobs/handlers/cleanup_sessions_job.rb', line 10 def perform(payload) retention = payload[:retention_days] || RETENTION_DAYS cutoff = (Time.now - (retention * 86_400)).utc.iso8601 db = Rubino.database.db old_sessions = db[:sessions] .where(status: "ended") .where { ended_at < cutoff } .select(:id) .all repo = Session::Repository.new old_sessions.each do |s| repo.destroy!(s[:id]) end # Evict orphaned/oversized spill + paste files past the age/size # budget (#374). destroy! above already removes the files of the # sessions it deleted; this also reaps spills whose session row is # long gone, never-cleaned-up tool-result spills from one-shot runs # (no session destroy ever fires), and anything over the total-size # budget. Best-effort inside the module. Util::SpillStore.evict!( max_age_seconds: payload[:spill_max_age_seconds] || Util::SpillStore::DEFAULT_MAX_AGE_SECONDS, max_total_bytes: payload[:spill_max_total_bytes] || Util::SpillStore::DEFAULT_MAX_TOTAL_BYTES ) end |