From e72cf3382bb7834ea95ddc44c5b9616150973f4c Mon Sep 17 00:00:00 2001 From: Heiko Bernloehr Date: Wed, 28 Feb 2018 22:21:39 +0100 Subject: [PATCH] Add garbage collecting tasks. New environment variables: ECS_PARTICIPANTS_TTL_SUB: Number of days created before garbage collected ECS_PARTICIPANTS_TTL_ANONYMOUS: Number of days created before garbage collected --- config/ecs_config.yml | 2 + config/initializers/ecs_00.rb | 12 +++--- ...ecs_garbage_collect_anonymous_participants.rake | 46 +++++++++------------ .../tasks/ecs_garbage_collect_auths.rake | 38 +++++------------ .../ecs_garbage_collect_sub_participants.rake | 48 ++++++++++------------ 5 files changed, 61 insertions(+), 85 deletions(-) copy config/initializers/ecs_00.rb => lib/tasks/ecs_garbage_collect_anonymous_participants.rake (52%) copy config/initializers/ecs_00.rb => lib/tasks/ecs_garbage_collect_auths.rake (52%) copy config/initializers/ecs_00.rb => lib/tasks/ecs_garbage_collect_sub_participants.rake (52%) diff --git a/config/ecs_config.yml b/config/ecs_config.yml index 77cebb0..aa4834e 100644 --- a/config/ecs_config.yml +++ b/config/ecs_config.yml @@ -1,5 +1,7 @@ participants: allow_anonymous: false + ttl_anonymous: 1 # number of days created before garbage collected + ttl_sub: 1 # number of days created before garbage collected allow_events: true # for database migration admin: confirm_actions: false diff --git a/config/initializers/ecs_00.rb b/config/initializers/ecs_00.rb index fa7a179..6869046 100644 --- a/config/initializers/ecs_00.rb +++ b/config/initializers/ecs_00.rb @@ -1,17 +1,17 @@ -# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# Copyright (C) 2007, 2008, 2009, 2010, 2018 Heiko Bernloehr (FreeIT.de). +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . @@ -38,3 +38,5 @@ end ECS_CONFIG["participants"]["allow_anonymous"] ||= false ECS_CONFIG["participants"]["allow_events"] ||= true ECS_CONFIG["admin"]["confirm_actions"] ||= true +ECS_CONFIG["participants"]["ttl_sub"] = ENV["ECS_PARTICIPANTS_TTL_SUB"] || ECS_CONFIG["participants"]["ttl_sub"] || 1 +ECS_CONFIG["participants"]["ttl_anonymous"] = ENV["ECS_PARTICIPANTS_TTL_ANONYMOUS"] || ECS_CONFIG["participants"]["ttl_anonymous"] || 1 diff --git a/config/initializers/ecs_00.rb b/lib/tasks/ecs_garbage_collect_anonymous_participants.rake similarity index 52% copy from config/initializers/ecs_00.rb copy to lib/tasks/ecs_garbage_collect_anonymous_participants.rake index fa7a179..8c87cac 100644 --- a/config/initializers/ecs_00.rb +++ b/lib/tasks/ecs_garbage_collect_anonymous_participants.rake @@ -1,40 +1,34 @@ -# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# Copyright (C) 2018 Heiko Bernloehr (FreeIT.de). +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . +namespace :ecs do + desc "Delete outtimed anonymous participants." + task :gc_anonymous_participants => :environment do -# Filter-Namespace -module EcsFilter + ttl= ECS_CONFIG["participants"]["ttl_anonymous"] + num= 0 + Participant.only_anonymous.each do |p| + if p.created_at <= ttl + p.destroy + num+=1 + end + end + txt= "gc_anonymous_participants: Number of deleted outtimed anonymous participants: #{num}" + puts txt + Rails.logger.info txt + end end - -class FilterApi - attr_accessor :params, :record -end - -FILTER_API=FilterApi.new - -# read configuration data -require 'yaml' - -begin - ECS_CONFIG = YAML::load_stream(File.open(Rails.root.join('config','ecs_config.yml')))[0] -rescue Exception - Rails.logger.fatal "Reading #{Rails.root.join('config','ecs_config.yml')}" -end - -ECS_CONFIG["participants"]["allow_anonymous"] ||= false -ECS_CONFIG["participants"]["allow_events"] ||= true -ECS_CONFIG["admin"]["confirm_actions"] ||= true diff --git a/config/initializers/ecs_00.rb b/lib/tasks/ecs_garbage_collect_auths.rake similarity index 52% copy from config/initializers/ecs_00.rb copy to lib/tasks/ecs_garbage_collect_auths.rake index fa7a179..ad1f530 100644 --- a/config/initializers/ecs_00.rb +++ b/lib/tasks/ecs_garbage_collect_auths.rake @@ -1,40 +1,24 @@ -# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# Copyright (C) 2018 Heiko Bernloehr (FreeIT.de). +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . +# - -# Filter-Namespace -module EcsFilter -end - -class FilterApi - attr_accessor :params, :record -end - -FILTER_API=FilterApi.new - -# read configuration data -require 'yaml' - -begin - ECS_CONFIG = YAML::load_stream(File.open(Rails.root.join('config','ecs_config.yml')))[0] -rescue Exception - Rails.logger.fatal "Reading #{Rails.root.join('config','ecs_config.yml')}" +namespace :ecs do + desc "Delete outtimed authorization tokens." + task :gc_sys_auths => :environment do + Auth.gc_outtimed + end end - -ECS_CONFIG["participants"]["allow_anonymous"] ||= false -ECS_CONFIG["participants"]["allow_events"] ||= true -ECS_CONFIG["admin"]["confirm_actions"] ||= true diff --git a/config/initializers/ecs_00.rb b/lib/tasks/ecs_garbage_collect_sub_participants.rake similarity index 52% copy from config/initializers/ecs_00.rb copy to lib/tasks/ecs_garbage_collect_sub_participants.rake index fa7a179..046e36e 100644 --- a/config/initializers/ecs_00.rb +++ b/lib/tasks/ecs_garbage_collect_sub_participants.rake @@ -1,40 +1,34 @@ -# Copyright (C) 2007, 2008, 2009, 2010 Heiko Bernloehr (FreeIT.de). -# +# Copyright (C) 2018 Heiko Bernloehr (FreeIT.de). +# # This file is part of ECS. -# +# # ECS is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of # the License, or (at your option) any later version. -# +# # ECS is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public # License along with ECS. If not, see . +# - -# Filter-Namespace -module EcsFilter -end - -class FilterApi - attr_accessor :params, :record -end - -FILTER_API=FilterApi.new - -# read configuration data -require 'yaml' - -begin - ECS_CONFIG = YAML::load_stream(File.open(Rails.root.join('config','ecs_config.yml')))[0] -rescue Exception - Rails.logger.fatal "Reading #{Rails.root.join('config','ecs_config.yml')}" +namespace :ecs do + desc "Delete outtimed subparticipants." + task :gc_sub_participants => :environment do + ttl= ECS_CONFIG["participants"]["ttl_sub"] + num= 0 + Participant.only_subparticipants.each do |p| + if p.created_at <= ttl + p.destroy + num+=1 + end + end + txt= "gc_sub_participants: Number of deleted subparticipants: #{num}" + puts txt + Rails.logger.info txt + end end - -ECS_CONFIG["participants"]["allow_anonymous"] ||= false -ECS_CONFIG["participants"]["allow_events"] ||= true -ECS_CONFIG["admin"]["confirm_actions"] ||= true -- 2.11.4.GIT