allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject git commit: [#5705] Add delay to update bin counts task
Date Fri, 08 Feb 2013 22:03:21 GMT
Updated Branches:
  refs/heads/tv/5705 [created] c66d90b33


[#5705] Add delay to update bin counts task


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

Branch: refs/heads/tv/5705
Commit: c66d90b33631050f89135b2473adb4b58fb6cd00
Parents: e096621
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Fri Feb 8 22:02:39 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Fri Feb 8 22:02:39 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/decorators.py           |    5 +++--
 Allura/allura/model/monq_model.py         |    9 ++++++---
 ForgeTracker/forgetracker/model/ticket.py |    2 +-
 3 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c66d90b3/Allura/allura/lib/decorators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/decorators.py b/Allura/allura/lib/decorators.py
index bd26b1e..a8ad5ec 100644
--- a/Allura/allura/lib/decorators.py
+++ b/Allura/allura/lib/decorators.py
@@ -14,7 +14,8 @@ def task(func):
     '''Decorator to add some methods to task functions'''
     def post(*args, **kwargs):
         from allura import model as M
-        return M.MonQTask.post(func, args, kwargs)
+        delay = kwargs.pop('delay', 0)
+        return M.MonQTask.post(func, args, kwargs, delay=delay)
     func.post = post
     return func
 
@@ -195,4 +196,4 @@ def memoize(func, *args):
     else:
         result = func(*args)
         dic[args] = result
-        return result
\ No newline at end of file
+        return result

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c66d90b3/Allura/allura/model/monq_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index 62b8fc4..3ec5e77 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -2,7 +2,7 @@ import sys
 import time
 import traceback
 import logging
-from datetime import datetime
+from datetime import datetime, timedelta
 
 import pymongo
 from pylons import c, g
@@ -113,7 +113,8 @@ class MonQTask(MappedClass):
              args=None,
              kwargs=None,
              result_type='forget',
-             priority=10):
+             priority=10,
+             delay=0):
         '''Create a new task object based on the current context.'''
         if args is None: args = ()
         if kwargs is None: kwargs = {}
@@ -141,7 +142,8 @@ class MonQTask(MappedClass):
             kwargs=kwargs,
             process=None,
             result=None,
-            context=context)
+            context=context,
+            time_queue=datetime.utcnow() + timedelta(seconds=delay))
         session(obj).flush(obj)
         try:
             if g.amq_conn:
@@ -164,6 +166,7 @@ class MonQTask(MappedClass):
         while True:
             try:
                 query = dict(state=state)
+                query['time_queue'] = {'$lt': datetime.utcnow()}
                 if only:
                     query['task_name'] = {'$in': only}
                 obj = cls.query.find_and_modify(

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/c66d90b3/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 96f3f7e..ada1cae 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -162,7 +162,7 @@ class Globals(MappedClass):
             return
         self._bin_counts_invalidated = datetime.utcnow()
         from forgetracker import tasks  # prevent circular import
-        tasks.update_bin_counts.post(self.app_config_id)
+        tasks.update_bin_counts.post(self.app_config_id, delay=5)
 
     def sortable_custom_fields_shown_in_search(self):
         return [dict(sortable_name='%s_s' % field['name'],


Mime
View raw message