mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 12:51:42 +00:00
abl
This commit is contained in:
parent
1e0fb95825
commit
9fefc0f554
1 changed files with 47 additions and 0 deletions
47
app/services/cleanup_service.rb
Normal file
47
app/services/cleanup_service.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Realiza tareas de limpieza en todos los sitios, para optimizar y
|
||||
# liberar espacio.
|
||||
class CleanupService
|
||||
# Días de antigüedad de los sitios
|
||||
attr_reader :before
|
||||
|
||||
# @param :before [ActiveSupport::TimeWithZone] Cuánto tiempo lleva sin usarse un sitio.
|
||||
def initialize(before: 30.days.ago)
|
||||
@before = before
|
||||
end
|
||||
|
||||
# Limpieza general
|
||||
#
|
||||
# @return [nil]
|
||||
def cleanup_everything!
|
||||
cleanup_older_sites!
|
||||
cleanup_newer_sites!
|
||||
end
|
||||
|
||||
# Encuentra todos los sitios sin actualizar y realiza limpieza.
|
||||
#
|
||||
# @return [nil]
|
||||
def cleanup_older_sites!
|
||||
Site.where('updated_at < ?', before).find_each do |site|
|
||||
next unless File.directory? site.path
|
||||
|
||||
site.deploys.find_each(&:cleanup!)
|
||||
|
||||
site.repository.gc
|
||||
site.touch
|
||||
end
|
||||
end
|
||||
|
||||
# Tareas para los sitios en uso
|
||||
#
|
||||
# @return [nil]
|
||||
def cleanup_newer_sites!
|
||||
Site.where('updated_at >= ?', before).find_each do |site|
|
||||
next unless File.directory? site.path
|
||||
|
||||
site.repository.gc
|
||||
site.touch
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue