• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2010 Google Inc. All rights reserved.
2#
3# Redistribution and use in source and binary forms, with or without
4# modification, are permitted provided that the following conditions are
5# met:
6#
7#     * Redistributions of source code must retain the above copyright
8# notice, this list of conditions and the following disclaimer.
9#     * Redistributions in binary form must reproduce the above
10# copyright notice, this list of conditions and the following disclaimer
11# in the documentation and/or other materials provided with the
12# distribution.
13#     * Neither the name of Google Inc. nor the names of its
14# contributors may be used to endorse or promote products derived from
15# this software without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29from google.appengine.ext import webapp, db
30from google.appengine.ext.webapp import template
31
32from handlers.updatebase import UpdateBase
33from model.attachment import Attachment
34from model.queues import Queue
35
36
37class ReleasePatch(UpdateBase):
38    def get(self):
39        self.response.out.write(template.render("templates/releasepatch.html", None))
40
41    def post(self):
42        queue_name = self.request.get("queue_name")
43        # FIXME: This queue lookup should be shared between handlers.
44        queue = Queue.queue_with_name(queue_name)
45        if not queue:
46            self.error(404)
47            return
48
49        attachment_id = self._int_from_request("attachment_id")
50        attachment = Attachment(attachment_id)
51        last_status = attachment.status_for_queue(queue)
52
53        # Ideally we should use a transaction for the calls to
54        # WorkItems and ActiveWorkItems.
55
56        # Only remove it from the queue if the last message is not a retry request.
57        # Allow removing it from the queue even if there is no last_status for easier testing.
58        if not last_status or not last_status.is_retry_request():
59            queue.work_items().remove_work_item(attachment_id)
60
61        # Always release the lock on the item.
62        queue.active_work_items().expire_item(attachment_id)
63