[error-report-web][PATCH 3/5] Allow alternate settings, avoid out of memory condition


Michael Halstead
 

From: Michael Halstead <mhalstead@linxufoundation.org>

---
Post/purge.py | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/Post/purge.py b/Post/purge.py
index 829fada..1289d13 100644
--- a/Post/purge.py
+++ b/Post/purge.py
@@ -1,4 +1,4 @@
-from datetime import datetime
+from datetime import datetime, timedelta
from django.utils import timezone
import os
import sys
@@ -8,22 +8,19 @@ def setup_django():
# Get access to our Django model
newpath = os.path.abspath(os.path.dirname(__file__)) + '/..'
sys.path.append(newpath)
- os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
+ if not os.getenv('DJANGO_SETTINGS_MODULE'):
+ os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
django.setup()

def main():
setup_django()
from Post.models import BuildFailure
- items = BuildFailure.objects.all()
- now = timezone.now()
+ delete_before = timezone.now()-timedelta(days=30)
+ query = "SELECT bf.id FROM Post_buildfailure bf LEFT JOIN Post_build b ON (bf.BUILD_id = b.id) WHERE bf.REFERER NOT IN ('OTHER','NO_REFERER') AND b.DATE < '{0}'".format(delete_before.date())
+ print query
+ items = BuildFailure.objects.raw(query)
for item in items:
- if item.REFERER == 'OTHER' or item.REFERER == 'NO_REFERER':
- continue
- difference = now - item.BUILD.DATE
- if difference.days > 30:
- item.delete()
+ item.delete()

if __name__ == "__main__":
main()
-
-
--
2.11.0