5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-18 08:36:22 +00:00

Merge branch 'issue-12854' into panel.sutty.nl

This commit is contained in:
f 2023-03-29 15:27:42 -03:00
commit fe2c2b5220
6 changed files with 25 additions and 6 deletions

View file

@ -1,6 +1,9 @@
# frozen_string_literal: true
puts 'Usa haini.sh para generar un entorno de trabajo reproducible'
if ENV['RAILS_ENV'] != 'production' && ENV['HAIN_ENV'].nil?
puts 'Usa haini.sh para generar un entorno de trabajo reproducible'
end
source 'https://gems.sutty.nl'
ruby '~> 2.7'

View file

@ -2,3 +2,4 @@ cleanup: bundle exec rake cleanup:everything
stats: bundle exec rake stats:process_all
distributed_press_renew_tokens: bundle exec rake distributed_press:tokens:renew
que: daemonize -c /srv/ -p /srv/tmp/que.pid -u rails /usr/local/bin/syslogize bundle exec que
emergency_cleanup: bundle exec rake cleanup:everything BEFORE=7

8
app/jobs/cleanup_job.rb Normal file
View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
# Realiza tareas de limpieza en segundo plano
class CleanupJob < ApplicationJob
def perform(before = nil)
CleanupService.new(before: before).cleanup_everything!
end
end

View file

@ -23,9 +23,11 @@ class CleanupService
#
# @return [nil]
def cleanup_older_sites!
Site.where('updated_at < ?', before).find_each do |site|
Site.where('updated_at < ?', before).order(updated_at: :desc).find_each do |site|
next unless File.directory? site.path
Rails.logger.info "Limpiando dependencias, archivos temporales y repositorio git de #{site.name}"
site.deploys.find_each(&:cleanup!)
site.repository.gc
@ -37,9 +39,11 @@ class CleanupService
#
# @return [nil]
def cleanup_newer_sites!
Site.where('updated_at >= ?', before).find_each do |site|
Site.where('updated_at >= ?', before).order(updated_at: :desc).find_each do |site|
next unless File.directory? site.path
Rails.logger.info "Limpiando repositorio git de #{site.name}"
site.repository.gc
site.touch
end

View file

@ -2,10 +2,9 @@
namespace :cleanup do
desc 'Cleanup sites'
task everything: :environment do
task everything: :environment do |_, args|
before = ENV.fetch('BEFORE', '30').to_i.days.ago
service = CleanupService.new(before: before)
service.cleanup_everything!
CleanupJob.perform_later(before)
end
end

View file

@ -22,3 +22,7 @@ check program distributed_press_tokens_renew
check process que with pidfile /srv/tmp/que.pid
start program = "/usr/bin/foreman run -f /srv/Procfile -d /srv que"
stop program = "/bin/sh -c 'cat /srv/tmp/que.pid | xargs -r kill'"
check filesystem root with path /
if space usage > 80% for 5 times within 15 cycles then alert
if space usage > 90% for 5 cycles then exec "/usr/bin/foreman run -f /srv/Procfile -d /srv emergency_cleanup" as uid "rails" gid "www-data"