summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2018-02-28 22:21:39 +0100
committerHeiko Bernloehr <Heiko.Bernloehr@FreeIT.de>2018-03-20 13:41:54 +0100
commite72cf3382bb7834ea95ddc44c5b9616150973f4c (patch)
tree6db5a83b5bacb04619e4cf81d8dfd08596ca2213 /lib
parent674c47bc2cedf71f7f52ce07052fed8c0c3578d6 (diff)
downloadecs-e72cf3382bb7834ea95ddc44c5b9616150973f4c.tar.gz
ecs-e72cf3382bb7834ea95ddc44c5b9616150973f4c.zip
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
Diffstat (limited to 'lib')
-rw-r--r--lib/tasks/ecs_garbage_collect_anonymous_participants.rake34
-rw-r--r--lib/tasks/ecs_garbage_collect_auths.rake24
-rw-r--r--lib/tasks/ecs_garbage_collect_sub_participants.rake34
3 files changed, 92 insertions, 0 deletions
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