releasepatch.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Copyright (C) 2013 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. from google.appengine.ext import webapp, db
  29. from google.appengine.ext.webapp import template
  30. from handlers.updatebase import UpdateBase
  31. from loggers.recordpatchevent import RecordPatchEvent
  32. from model.attachment import Attachment
  33. from model.queues import Queue
  34. class ReleasePatch(UpdateBase):
  35. def get(self):
  36. self.response.out.write(template.render("templates/releasepatch.html", None))
  37. def post(self):
  38. queue_name = self.request.get("queue_name")
  39. # FIXME: This queue lookup should be shared between handlers.
  40. queue = Queue.queue_with_name(queue_name)
  41. if not queue:
  42. self.error(404)
  43. return
  44. attachment_id = self._int_from_request("attachment_id")
  45. attachment = Attachment(attachment_id)
  46. last_status = attachment.status_for_queue(queue)
  47. # Ideally we should use a transaction for the calls to
  48. # WorkItems and ActiveWorkItems.
  49. # Only remove it from the queue if the last message is not a retry request.
  50. # Allow removing it from the queue even if there is no last_status for easier testing.
  51. if not last_status or not last_status.is_retry_request():
  52. queue.work_items().remove_work_item(attachment_id)
  53. RecordPatchEvent.stopped(attachment_id, queue_name)
  54. else:
  55. RecordPatchEvent.retrying(attachment_id, queue_name)
  56. # Always release the lock on the item.
  57. queue.active_work_items().expire_item(attachment_id)