incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [11/16] git commit: [#6905] Refactored
Date Fri, 10 Jan 2014 15:58:08 GMT
[#6905] Refactored

Signed-off-by: Tim Van Steenburgh <tvansteenburgh@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/62f4b4fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/62f4b4fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/62f4b4fe

Branch: refs/heads/cj/7005
Commit: 62f4b4fec8df16ff387fba2df64e5c3e711959d1
Parents: 3f9104f
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Thu Jan 9 17:53:11 2014 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Jan 9 20:34:50 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/repository.py         |  7 +++--
 Allura/allura/lib/decorators.py                 |  3 +--
 Allura/allura/model/monq_model.py               |  6 -----
 Allura/allura/model/repository.py               | 27 ++++++--------------
 Allura/allura/tasks/repo_tasks.py               |  7 +++--
 Allura/allura/templates/repo/tarball.html       | 17 ++++++------
 .../tests/functional/test_controllers.py        |  4 +--
 .../forgegit/tests/model/test_repository.py     | 11 +++-----
 8 files changed, 30 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/controllers/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/repository.py b/Allura/allura/controllers/repository.py
index 0dc1274..2ca33ca 100644
--- a/Allura/allura/controllers/repository.py
+++ b/Allura/allura/controllers/repository.py
@@ -466,10 +466,9 @@ class CommitBrowser(BaseController):
             raise exc.HTTPNotFound()
         rev = self._commit.url().split('/')[-2]
         status = c.app.repo.get_tarball_status(rev, path)
-        if status in (None, 'error') and request.method == 'POST':
-            allura.tasks.repo_tasks.tarball.post(revision=rev, path=path)
+        if not status and request.method == 'POST':
+            allura.tasks.repo_tasks.tarball.post(rev, path)
             redirect('tarball' + '?path={0}'.format(path) if path else '')
-        status = 'na' if status in (None, 'error') else status
         return dict(commit=self._commit, revision=rev, status=status)
 
     @expose('json:')
@@ -477,7 +476,7 @@ class CommitBrowser(BaseController):
         if not asbool(tg.config.get('scm.repos.tarball.enable', False)):
             raise exc.HTTPNotFound()
         rev = self._commit.url().split('/')[-2]
-        return dict(status=c.app.repo.get_tarball_status(rev, path) or 'na')
+        return dict(status=c.app.repo.get_tarball_status(rev, path))
 
 
     @expose('jinja:allura:templates/repo/log.html')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/lib/decorators.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/decorators.py b/Allura/allura/lib/decorators.py
index 5810fb0..8604a92 100644
--- a/Allura/allura/lib/decorators.py
+++ b/Allura/allura/lib/decorators.py
@@ -59,8 +59,7 @@ def task(*args, **kw):
                     kw.get('notifications_disabled') else h.null_contextmanager)
             with cm(project):
                 from allura import model as M
-                task_obj = M.MonQTask.post(func, args, kwargs, delay=delay)
-            return task_obj
+                return M.MonQTask.post(func, args, kwargs, delay=delay)
         # if decorating a class, have to make it a staticmethod
         # or it gets a spurious cls argument
         func.post = staticmethod(post) if inspect.isclass(func) else post

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/model/monq_model.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/monq_model.py b/Allura/allura/model/monq_model.py
index 7e25f38..c5d3431 100644
--- a/Allura/allura/model/monq_model.py
+++ b/Allura/allura/model/monq_model.py
@@ -76,12 +76,7 @@ class MonQTask(MappedClass):
                 # have an index on task_name
                 'state', 'task_name', 'time_queue'
             ],
-            [
-                # used while user quering snapsot
-                'kwargs.revision', 'kwargs.path'
-            ],
             'args',
-            'time_queue',
         ]
 
     _id = FieldProperty(S.ObjectId)
@@ -252,7 +247,6 @@ class MonQTask(MappedClass):
         old_cuser = getattr(c, 'user', None)
         try:
             func = self.function
-            func.task_id = str(self._id)
             c.project = M.Project.query.get(_id=self.context.project_id)
             c.app = None
             if c.project:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 93e012e..252210e 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -357,31 +357,20 @@ class Repository(Artifact, ActivityObject):
                          filename)
         return urljoin(tg.config.get('scm.repos.tarball.url_prefix', '/'), r)
 
-    def get_tarball_status(self, revision, path=None, task_id=None):
+    def get_tarball_status(self, revision, path=None):
         pathname = os.path.join(self.tarball_path, self.tarball_filename(revision, path))
         filename = '%s%s' % (pathname, '.zip')
-        tmpfilename = '%s%s' % (pathname, '.tmp')
-
-        # check for state of task in MonQTask
-        path = '' if path is None else path
-        task_query = MonQTask.query.find({
-            'task_name': 'allura.tasks.repo_tasks.tarball',
-            '$or': [
-                {'kwargs.path': path, 'kwargs.revision': revision},
-                {'args':[revision, path]}]})
-        task = task_query.sort(
-            [('time_queue', pymongo.DESCENDING),]).limit(1).first()
-
         if os.path.isfile(filename):
             return 'complete'
 
-        if not task or \
-            (task.state == 'complete' and not os.path.isfile(filename)):
-            return None
-        if task.state == 'busy' and str(task._id) == task_id:
-            return 'self'
+        # file doesn't exist, check for busy task
+        task = MonQTask.query.get(**{
+            'task_name': 'allura.tasks.repo_tasks.tarball',
+            'args': [revision, path or ''],
+            'state': {'$in': ['busy', 'ready']},
+            })
 
-        return task.state
+        return task.state if task else None
 
 
     def __repr__(self): # pragma no cover

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/tasks/repo_tasks.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tasks/repo_tasks.py b/Allura/allura/tasks/repo_tasks.py
index ab0a430..978f027 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -120,13 +120,12 @@ def reclone_repo(*args, **kwargs):
         g.post_event('repo_clone_task_failed', source_url, source_path, traceback.format_exc())
 
 @task
-def tarball(revision=None, path=None):
+def tarball(revision, path):
     log = logging.getLogger(__name__)
     if revision:
         repo = c.app.repo
-        status = repo.get_tarball_status(revision, path,
-            task_id=tarball.task_id)
-        if status in ('busy', 'complete'):
+        status = repo.get_tarball_status(revision, path)
+        if status == 'complete':
             log.info('Skipping snapshot for repository: %s:%s rev %s because it is already
%s' %
                      (c.project.shortname, c.app.config.options.mount_point, revision, status))
         else:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/Allura/allura/templates/repo/tarball.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/tarball.html b/Allura/allura/templates/repo/tarball.html
index d95c7e2..92b7af4 100644
--- a/Allura/allura/templates/repo/tarball.html
+++ b/Allura/allura/templates/repo/tarball.html
@@ -53,25 +53,27 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a>
{{commit_labels(
             left: 10 // Left position relative to parent in px
         };
         var spinner = new Spinner(opts).spin($('#snapshot_status')[0]);
-        var delay = 500;
+        var delay = 500, elapsed = 0;
+        $('#snapshot_status h2.busy').show();
         function check_status() {
             $.get('{{commit.url()}}tarball_status?path={{path}}', function(data) {
                 if (data.status === 'complete') {
                     spinner.stop();
                     $('#snapshot_status h2').hide();
-                    $('#snapshot_status h2.' + data.status).show();
+                    $('#snapshot_status h2.complete').show();
                     {% if 'no-redirect' not in request.params %}
                         window.location.href = '{{c.app.repo.tarball_url(revision, path)}}';
                     {% endif %}
                 } else {
-                    $('#snapshot_status h2').hide();
-                    if (data.status === 'na' || data.status === 'error') {
-                        spinner.stop();
+                    if (data.status === 'ready' || data.status === 'busy') {
+                        // keep waiting
+                    } else if (data.status === 'error' || elapsed > 5000) {
                         // something went wrong
+                        spinner.stop();
+                        $('#snapshot_status h2').hide();
                         $('#snapshot_status form').show();
-                    } else {
-                        $('#snapshot_status h2.busy').show();
                     }
+                    elapsed += delay;
                     if (delay < 60000){
                         delay = delay * 2;
                     }
@@ -90,7 +92,6 @@ Commit <a href="{{commit.url()}}">{{commit.shorthand_id()}}</a>
{{commit_labels(
 <div id='snapshot_status'>
     <h2 class="busy">Generating snapshot...</h2>
     <h2 class="complete">Your download will begin shortly, or use this <a href="{{c.app.repo.tarball_url(revision,
path)}}">direct link</a>.</h2>
-    <h2 class="na">Checking snapshot status...</h2>
     <form action="tarball" method="post">
       <p>We're having trouble finding that snapshot. Would you like to resubmit?</p>
       <input type="hidden" name="path" value="{{path}}" />

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index 495187a..f1c8a49 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -346,9 +346,9 @@ class TestRootController(_TestCase):
         assert '/p/test/src-git/ci/master/tarball' in r
         assert 'Download Snapshot' in r
         r = self.app.post('/p/test/src-git/ci/master/tarball').follow()
-        assert 'Checking snapshot status...' in r
+        assert 'Generating snapshot...' in r
         r = self.app.get('/p/test/src-git/ci/master/tarball')
-        assert 'Checking snapshot status...' in r
+        assert 'Generating snapshot...' in r
         M.MonQTask.run_ready()
         ThreadLocalORMSession.flush_all()
         r = self.app.get(ci + 'tarball_status')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/62f4b4fe/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index 3680846..33875bd 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -411,14 +411,11 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
         # task created
         assert_equal(self.repo.get_tarball_status('HEAD'), 'ready')
 
-        task = M.MonQTask.query.find({
+        task = M.MonQTask.query.get(**{
             'task_name': 'allura.tasks.repo_tasks.tarball',
-            '$or': [
-                {'kwargs':
-                    {'path': '',
-                     'revision': 'HEAD'}},
-                    {'args':['HEAD', '']}]
-            }).sort([('time_queue', pymongo.DESCENDING),]).limit(1).first()
+            'args': ['HEAD', ''],
+            'state': {'$in': ['busy', 'ready']},
+            })
 
         # task is running
         task.state = 'busy'


Mime
View raw message