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 29 from google.appengine.ext import webapp, db 30 from google.appengine.ext.webapp import template 31 32 from handlers.updatebase import UpdateBase 33 from model.attachment import Attachment 34 from model.queues import Queue 35 36 37 class SubmitToEWS(UpdateBase): 38 def get(self): 39 self.response.out.write(template.render("templates/submittoews.html", None)) 40 41 def _should_add_to_ews_queue(self, queue, attachment): 42 # This assert() is here to make sure we're not submitting to the commit-queue. 43 # The commit-queue clients check each patch anyway, but there is not sense 44 # in adding things to the commit-queue when they won't be processed by it. 45 assert(queue.is_ews()) 46 latest_status = attachment.status_for_queue(queue) 47 if not latest_status: 48 return True 49 # Only ever re-submit to the EWS if the EWS specifically requested a retry. 50 # This allows us to restart the EWS feeder queue, without all r? patches 51 # being retried as a result of that restart! 52 # In some future version we might add a "force" button to allow the user 53 # to override this restriction. 54 return latest_status.is_retry_request() 55 56 def _add_attachment_to_ews_queues(self, attachment): 57 for queue in Queue.all_ews(): # all_ews() currently includes the style-queue 58 if self._should_add_to_ews_queue(queue, attachment): 59 queue.work_items().add_work_item(attachment.id) 60 61 def post(self): 62 attachment_id = self._int_from_request("attachment_id") 63 attachment = Attachment(attachment_id) 64 self._add_attachment_to_ews_queues(attachment) 65