diff options
-rw-r--r-- | config/ecs_config.yml | 2 | ||||
-rw-r--r-- | config/initializers/ecs_00.rb | 12 | ||||
-rw-r--r-- | lib/tasks/ecs_garbage_collect_anonymous_participants.rake | 34 | ||||
-rw-r--r-- | lib/tasks/ecs_garbage_collect_auths.rake | 24 | ||||
-rw-r--r-- | lib/tasks/ecs_garbage_collect_sub_participants.rake | 34 |
5 files changed, 101 insertions, 5 deletions
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 <http://www.gnu.org/licenses/>. @@ -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/lib/tasks/ecs_garbage_collect_anonymous_participants.rake b/lib/tasks/ecs_garbage_collect_anonymous_participants.rake new file mode 100644 index 0000000..8c87cac --- /dev/null +++ b/lib/tasks/ecs_garbage_collect_anonymous_participants.rake @@ -0,0 +1,34 @@ +# 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 <http://www.gnu.org/licenses/>. + +namespace :ecs do + desc "Delete outtimed anonymous participants." + task :gc_anonymous_participants => :environment do + + 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 diff --git a/lib/tasks/ecs_garbage_collect_auths.rake b/lib/tasks/ecs_garbage_collect_auths.rake new file mode 100644 index 0000000..ad1f530 --- /dev/null +++ b/lib/tasks/ecs_garbage_collect_auths.rake @@ -0,0 +1,24 @@ +# 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 <http://www.gnu.org/licenses/>. +# + +namespace :ecs do + desc "Delete outtimed authorization tokens." + task :gc_sys_auths => :environment do + Auth.gc_outtimed + end +end diff --git a/lib/tasks/ecs_garbage_collect_sub_participants.rake b/lib/tasks/ecs_garbage_collect_sub_participants.rake new file mode 100644 index 0000000..046e36e --- /dev/null +++ b/lib/tasks/ecs_garbage_collect_sub_participants.rake @@ -0,0 +1,34 @@ +# 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 <http://www.gnu.org/licenses/>. +# + +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 |