[damned-lies] Run pull_code lengthy work in a separate thread



commit 05a380974cbdf5dc3efb955b5c4042517df0a8de
Author: Claude Paroz <claude 2xlibre net>
Date:   Tue Jun 12 20:39:38 2018 +0200

    Run pull_code lengthy work in a separate thread
    
    The webhook expects a response in a relatively short time frame to succeed.

 common/views.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/common/views.py b/common/views.py
index a0195bf0..8289cc8d 100644
--- a/common/views.py
+++ b/common/views.py
@@ -1,4 +1,5 @@
 from pathlib import Path
+from threading import Thread
 
 from django.conf import settings
 from django.contrib.auth import login, authenticate
@@ -133,7 +134,14 @@ def pull_code(request):
     if not verified:
         return HttpResponseForbidden()
 
-    run_shell_command(['git', 'pull', '--rebase'])
-    call_command('compile-trans', verbosity=0)
-    run_shell_command(['touch', 'wsgi.py'], cwd=Path(settings.BASE_DIR) / 'damnedlies')
+    # Run effective work in a separate thread to prevent timeouts
+    thread = Thread(target=pull_code_real)
+    thread.start()
     return HttpResponse('OK')
+
+
+def pull_code_real():
+    cwd = Path(settings.BASE_DIR) / 'damnedlies'
+    run_shell_command(['git', 'pull', '--rebase'], cwd=cwd)
+    call_command('compile-trans', verbosity=0)
+    run_shell_command(['touch', 'wsgi.py'], cwd=cwd)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]