def post(self): logging.debug('Begin mail-request-confirmation task handler') num_tries = self.request.headers['X-AppEngine-TaskRetryCount'] logging.info('Task has been executed %s times', num_tries) execution_key = self.request.get('key') if not execution_key: raise exceptions.MissingException('Missing "key" parameter.') execution = models.Execution.get(execution_key) if not execution.member: raise exceptions.InternalException( 'Execution "%s" has no email address.' % execution.id) if not isinstance(execution.action, models.Action): raise exceptions.InternalException( 'Execution "%s" has no action.' % execution.id) request = execution.request text_template_file = settings.TEMPLATE_DIR + \ '/email_confirmation_text.tpl' html_template_file = settings.TEMPLATE_DIR + \ '/email_confirmation_html.tpl' template_vars = { 'requestor': request.requestor, 'request_key': request.id, 'submitted_date': request.submitted_date, 'request_data': request.get_submitted_data(), 'step_name': execution.step.name, 'action_name': execution.action.name } text_body = template.render(text_template_file, template_vars) html_body = template.render(html_template_file, template_vars) message = mail.EmailMessage() message.sender = 'Flomosa <%s>' % settings.FEEDBACK_FORWARDER_EMAIL message.to = execution.member message.subject = '[flomosa] Request #%s' % request.id message.body = text_body message.html = html_body logging.info('Sending confirmation email to "%s".', execution.member) try: message.send() except apiproxy_errors.OverQuotaError: raise exceptions.QuotaException('Over email quota limit to send ' \ 'confirmation email to "%s".' % execution.member) except Exception: if not is_development(): raise exceptions.InternalException('Unable to send ' \ 'confirmation email to "%s".' % execution.member) logging.debug('Finished mail-request-confirmation task handler')
def post(self): logging.debug('Begin step-callback task handler') num_tries = self.request.headers['X-AppEngine-TaskRetryCount'] logging.info('Task has been executed %s times', num_tries) step_key = self.request.get('step_key') callback_url = self.request.get('callback_url') if not step_key: raise exceptions.MissingException('Missing "step_key" parameter.') if not callback_url: raise exceptions.MissingException( 'Missing "callback_url" parameter.') if is_development(): logging.info('Skip POST\'ing hub notifications in development.') return None step = models.Step.get(step_key) hub_data = urllib.urlencode({'hub.url': step.get_absolute_url(), 'hub.mode': 'publish'}, doseq=True) rpc = urlfetch.create_rpc(deadline=5) urlfetch.make_fetch_call(rpc, url=callback_url, payload=hub_data, method=urlfetch.POST, headers={'Content-Type': 'application/x-www-form-urlencoded'}) try: result = rpc.get_result() if result.status_code == 204: logging.info('Submitted POST request to "%s" for Step "%s".', callback_url, step.id) else: logging.warning('Received an HTTP status of "%s" when ' \ 'submitting POST request to "%s" for Step "%s".', result.status_code, callback_url, step.id) self.halt_requeue() except urlfetch.DownloadError, ex: logging.warning('Could not submit POST request to "%s" for ' \ 'Step "%s": %s.', callback_url, step.id, ex) self.halt_requeue()
def post(self): logging.debug('Begin mail-request-notify task handler') num_tries = self.request.headers['X-AppEngine-TaskRetryCount'] logging.info('Task has been executed %s times', num_tries) execution_key = self.request.get('key') if not execution_key: raise exceptions.MissingException('Missing "key" parameter.') execution = models.Execution.get(execution_key) if not execution.member: raise exceptions.InternalException( 'Execution "%s" has no email address.' % execution.id) if execution.sent_date: logging.warning('Execution "%s" notification already sent to ' \ '"%s". Exiting.', execution.id, execution.member) return None completed_execution = execution.is_step_completed() if completed_execution: logging.info('Step "%s" already completed by "%s". Exiting.', execution.step.id, completed_execution.member) return None request = execution.request step = execution.step text_template_file = settings.TEMPLATE_DIR + '/email_notify_text.tpl' html_template_file = settings.TEMPLATE_DIR + '/email_notify_html.tpl' template_vars = { 'execution_key': execution.id, 'actions': step.actions, 'requestor': request.requestor, 'request_key': request.id, 'submitted_date': request.submitted_date, 'request_data': request.get_submitted_data(), 'step_name': step.name, 'url': settings.HTTP_URL } text_body = template.render(text_template_file, template_vars) html_body = template.render(html_template_file, template_vars) message = mail.EmailMessage() message.sender = 'Flomosa <reply+%s@%s>' % (execution.id, settings.EMAIL_DOMAIN) message.to = execution.member message.subject = '[flomosa] Request #%s' % request.id message.body = text_body message.html = html_body logging.info('Sending email to "%s" for Execution "%s".', execution.member, execution.id) try: message.send() except apiproxy_errors.OverQuotaError: raise exceptions.QuotaException('Over email quota limit to send ' \ 'notification email to "%s".' % execution.member) except Exception: if not is_development(): raise exceptions.InternalException('Unable to send ' \ 'notification email to "%s": %s.' % execution.member) execution.set_sent() logging.debug('Finished mail-request-notify task handler')