You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/09/19 20:43:27 UTC

[24/50] git commit: [#4940] Added options to taskd to only or never process certain tasks by name

[#4940] Added options to taskd to only or never process certain tasks by name

Signed-off-by: Cory Johns <jo...@geek.net>


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

Branch: refs/heads/master
Commit: 7f4ce463d3fd19d45d123049d5bf06e11a9071b8
Parents: 5030fa8
Author: Cory Johns <jo...@geek.net>
Authored: Fri Sep 14 18:24:58 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Fri Sep 14 18:24:58 2012 +0000

----------------------------------------------------------------------
 Allura/allura/command/taskd.py    |   16 +++++++++++++++-
 Allura/allura/model/monq_model.py |   13 +++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7f4ce463/Allura/allura/command/taskd.py
----------------------------------------------------------------------
diff --git a/Allura/allura/command/taskd.py b/Allura/allura/command/taskd.py
index ba26a48..f04277a 100644
--- a/Allura/allura/command/taskd.py
+++ b/Allura/allura/command/taskd.py
@@ -20,6 +20,10 @@ class TaskdCommand(base.Command):
                       help='number of worker processes to spawn')
     parser.add_option('--dry_run', dest='dry_run', action='store_true', default=False,
                       help="get ready to run the task daemon, but don't actually run it")
+    parser.add_option('--only', dest='only', type='string', default=None,
+                      help='only handle tasks of the given name(s) (can be comma-separated list)')
+    parser.add_option('--exclude', dest='exclude', type='string', default=None,
+                      help='never handle tasks of the given name(s) (can be comma-separated list)')
 
     def command(self):
         self.basic_setup()
@@ -45,6 +49,12 @@ class TaskdCommand(base.Command):
         if self.options.dry_run: return
         wsgi_app = loadapp('config:%s#task' % self.args[0],relative_to=os.getcwd())
         poll_interval = asint(pylons.config.get('monq.poll_interval', 10))
+        only = self.options.only
+        if only:
+            only = only.split(',')
+        exclude = self.options.exclude
+        if exclude:
+            exclude = exclude.split(',')
         def start_response(status, headers, exc_info=None):
             pass
         def waitfunc_amqp():
@@ -63,7 +73,11 @@ class TaskdCommand(base.Command):
                 pylons.g.amq_conn.reset()
             try:
                 while True:
-                    task = M.MonQTask.get(process=name, waitfunc=waitfunc)
+                    task = M.MonQTask.get(
+                            process=name,
+                            waitfunc=waitfunc,
+                            only=only,
+                            exclude=exclude)
                     # Build the (fake) request
                     r = Request.blank('/--%s--/' % task.task_name, dict(task=task))
                     list(wsgi_app(r.environ, start_response))

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/7f4ce463/Allura/allura/model/monq_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index d40d321..94fe9a1 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -147,7 +147,7 @@ class MonQTask(MappedClass):
         return obj
 
     @classmethod
-    def get(cls, process='worker', state='ready', waitfunc=None):
+    def get(cls, process='worker', state='ready', waitfunc=None, only=None, exclude=None):
         '''Get the highest-priority, oldest, ready task and lock it to the
         current process.  If no task is available and waitfunc is supplied, call
         the waitfunc before trying to get the task again.  If waitfunc is None
@@ -158,8 +158,17 @@ class MonQTask(MappedClass):
                 ('time_queue', ming.ASCENDING)]
         while True:
             try:
+                query = dict(state=state)
+                if only:
+                    query['task_name'] = {'$in': only}
+                if exclude:
+                    nin = {'$nin': exclude}
+                    if 'task_name' not in query:
+                        query['task_name'] = nin
+                    else:
+                        query['task_name'] = {'$and': [query['task_name'], nin]}
                 obj = cls.query.find_and_modify(
-                    query=dict(state=state),
+                    query=query,
                     update={
                         '$set': dict(
                             state='busy',