You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/06/05 22:24:45 UTC

git commit: [#5328] Add task detail to work proc title

Updated Branches:
  refs/heads/tv/5328 [created] 028d1e31c


[#5328] Add task detail to work proc title

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/028d1e31
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/028d1e31
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/028d1e31

Branch: refs/heads/tv/5328
Commit: 028d1e31cc5ab1caabf10846611df18a0f4f9c5a
Parents: bf6db7f
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Wed Jun 5 20:24:29 2013 +0000
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Wed Jun 5 20:24:29 2013 +0000

----------------------------------------------------------------------
 Allura/allura/command/taskd.py |   33 ++++++++++++++++++++++++++-------
 requirements-common.txt        |    2 ++
 2 files changed, 28 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/028d1e31/Allura/allura/command/taskd.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/taskd.py b/Allura/allura/command/taskd.py
index f75f01b..75d5fcd 100644
--- a/Allura/allura/command/taskd.py
+++ b/Allura/allura/command/taskd.py
@@ -19,12 +19,15 @@ import logging
 import os
 import time
 import Queue
+from contextlib import contextmanager
 from datetime import datetime, timedelta
 import signal
 import sys
 
 import faulthandler
 import pylons
+from setproctitle import setproctitle, getproctitle
+
 from paste.deploy import loadapp
 from paste.deploy.converters import asint
 from webob import Request
@@ -36,6 +39,19 @@ faulthandler.enable()
 status_log = logging.getLogger('taskdstatus')
 
 
+@contextmanager
+def proctitle(title):
+    """Temporarily change the process title, then restore it."""
+    orig_title = getproctitle()
+    try:
+        setproctitle(title)
+        yield
+        setproctitle(orig_title)
+    except:
+        setproctitle(orig_title)
+        raise
+
+
 class TaskdCommand(base.Command):
     summary = 'Task server'
     parser = base.Command.standard_parser(verbose=True)
@@ -43,6 +59,7 @@ class TaskdCommand(base.Command):
                       help='only handle tasks of the given name(s) (can be comma-separated list)')
 
     def command(self):
+        setproctitle('taskd')
         self.basic_setup()
         self.keep_running = True
         self.restart_when_done = False
@@ -121,13 +138,15 @@ class TaskdCommand(base.Command):
                             waitfunc=waitfunc,
                             only=only)
                     if self.task:
-                        # Build the (fake) request
-                        r = Request.blank('/--%s--/%s/' % (self.task.task_name, self.task._id),
-                                          {'task': self.task,
-                                           'wsgi.errors': wsgi_error_log,  # ErrorMiddleware records error details here
-                                           })
-                        list(wsgi_app(r.environ, start_response))
-                        self.task = None
+                        with(proctitle("taskd:{0}:{1}".format(
+                            self.task.task_name, self.task._id))):
+                            # Build the (fake) request
+                            r = Request.blank('/--%s--/%s/' % (self.task.task_name, self.task._id),
+                                              {'task': self.task,
+                                               'wsgi.errors': wsgi_error_log,  # ErrorMiddleware records error details here
+                                               })
+                            list(wsgi_app(r.environ, start_response))
+                            self.task = None
             except Exception as e:
                 if self.keep_running:
                     base.log.exception('taskd error %s; pausing for 10s before taking more tasks' % e)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/028d1e31/requirements-common.txt
----------------------------------------------------------------------
diff --git a/requirements-common.txt b/requirements-common.txt
index f80e240..3efed47 100644
--- a/requirements-common.txt
+++ b/requirements-common.txt
@@ -37,6 +37,8 @@ python-dateutil==1.5
 python-magic==0.4.3
 python-openid==2.2.5
 pytidylib==0.2.1
+# for taskd proc name switching
+setproctitle==1.1.7
 # dep of pypeline
 textile==2.1.5
 # dep of colander