Пример #1
0
def query_done_cb(request, server_id):
    """
  A callback for query completion notification. When the query is done,
  BeeswaxServer notifies us by sending a GET request to this view.
  """
    message_template = '<html><head></head>%(message)s<body></body></html>'
    message = {'message': 'error'}

    try:
        query_history = QueryHistory.objects.get(server_id=server_id + '\n')

        # Update the query status
        query_history.set_to_available()

        # Find out details about the query
        if not query_history.notify:
            message['message'] = 'email_notify is false'
            return HttpResponse(message_template % message)

        design = query_history.design
        user = query_history.owner
        subject = _("Beeswax query completed.")

        if design:
            subject += ": %s" % (design.name, )

        link = "%s%s" % (get_desktop_uri_prefix(),
                         reverse(
                             get_app_name(request) + ':watch_query_history',
                             kwargs={'query_history_id': query_history.id}))
        body = _(
            "%(subject)s. See the results here: %(link)s\n\nQuery:\n%(query)s"
        ) % {
            'subject': subject,
            'link': link,
            'query': query_history.query
        }

        user.email_user(subject, body)
        message['message'] = 'sent'
    except Exception as ex:
        msg = "Failed to send query completion notification via e-mail: %s" % (
            ex)
        LOG.error(msg)
        message['message'] = msg
    return HttpResponse(message_template % message)
Пример #2
0
def query_done_cb(request, server_id):
    """
  A callback for query completion notification. When the query is done,
  BeeswaxServer notifies us by sending a GET request to this view.

  This view should always return a 200 response, to reflect that the
  notification is delivered to the right view.
  """
    message_template = "<html><head></head>%(message)s<body></body></html>"
    message = {"message": "error"}

    try:
        query_history = models.QueryHistory.objects.get(server_id=server_id)

        # Update the query status
        query_history.set_to_available()

        # Find out details about the query
        if not query_history.notify:
            message["message"] = "email_notify is false"
            return HttpResponse(message_template % message)

        design = query_history.design
        user = query_history.owner
        subject = _("Beeswax query completed")

        if design:
            subject += ": %s" % (design.name,)

        link = "%s%s" % (
            get_desktop_uri_prefix(),
            reverse(get_app_name(request) + ":watch_query", kwargs={"id": query_history.id}),
        )
        body = _("%(subject)s. You may see the results here: %(link)s\n\nQuery:\n%(query)s") % {
            "subject": subject,
            "link": link,
            "query": query_history.query,
        }

        user.email_user(subject, body)
        message["message"] = "sent"
    except Exception, ex:
        msg = "Failed to send query completion notification via e-mail: %s" % (ex)
        LOG.error(msg)
        message["message"] = msg
Пример #3
0
def query_done_cb(request, server_id):
  """
  A callback for query completion notification. When the query is done,
  BeeswaxServer notifies us by sending a GET request to this view.
  """
  message_template = '<html><head></head>%(message)s<body></body></html>'
  message = {'message': 'error'}

  try:
    query_history = QueryHistory.objects.get(server_id=server_id + '\n')

    # Update the query status
    query_history.set_to_available()

    # Find out details about the query
    if not query_history.notify:
      message['message'] = 'email_notify is false'
      return HttpResponse(message_template % message)

    design = query_history.design
    user = query_history.owner
    subject = _("Beeswax query completed.")

    if design:
      subject += ": %s" % (design.name,)

    link = "%s%s" % \
              (get_desktop_uri_prefix(),
               reverse(get_app_name(request) + ':watch_query_history', kwargs={'query_history_id': query_history.id}))
    body = _("%(subject)s. See the results here: %(link)s\n\nQuery:\n%(query)s") % {
               'subject': subject, 'link': link, 'query': query_history.query
             }

    user.email_user(subject, body)
    message['message'] = 'sent'
  except Exception, ex:
    msg = "Failed to send query completion notification via e-mail: %s" % (ex)
    LOG.error(msg)
    message['message'] = msg
Пример #4
0
def query_done_cb(request, server_id):
  """
  A callback for query completion notification. When the query is done,
  BeeswaxServer notifies us by sending a GET request to this view.

  This view should always return a 200 response, to reflect that the
  notification is delivered to the right view.
  """
  res = HttpResponse('<html><head></head><body></body></html>')

  history = models.QueryHistory.objects.get(server_id=server_id)

  if history is None:
    LOG.error('Processing query completion email: Cannot find query matching id %s' % (server_id,))
    return res

  # Update the query status
  history.save_state(models.QueryHistory.STATE.available)

  # Find out details about the query
  if not history.notify:
    return res
  design = history.design
  user = history.owner
  subject = _("Beeswax query completed")
  if design:
    subject += ": %s" % (design.name,)

  link = "%s/#launch=Beeswax:%s" % \
            (get_desktop_uri_prefix(),
             urlresolvers.reverse(watch_query, kwargs={'id': history.id}))
  body = _("%(subject)s. You may see the results here: %(link)s\n\nQuery:\n%(query)s") % {'subject': subject, 'link': link, 'query': history.query}
  try:
    user.email_user(subject, body)
  except Exception, ex:
    LOG.error("Failed to send query completion notification via e-mail to %s: %s" %
              (user.username, ex))
Пример #5
0
        completed = result['completed'] if 'completed' in result else None
        runState = result['status']['runState'] if 'status' in result and 'runState' in result['status'] else None
        if runState == job.TEMPLETON_JOB_RUN_STATE_KILLED:
            job.status = job.JOB_KILLED
        elif runState == job.TEMPLETON_JOB_RUN_STATE_FAILED or (completed and exitValue is not None and exitValue != 0):
            job.status = job.JOB_FAILED
    except Exception, ex:
        LOG.debug(unicode(ex))
    job.save()
    if job.email_notification:
        subject = 'Query result'
        body = "Your PIG script '%s' started at %s has been completed.\n\
        You can check result at the following link %s" % (
            job.script.title,
            job.start_time.strftime('%d.%m.%Y %H:%M'),
            "%s%s" % (get_desktop_uri_prefix(), reverse("query_history_job_detail", args=[job_id]))
        )
        job.script.user.email_user(subject, body)
    return HttpResponse("Done")


def autosave_scripts(request):
    request.session['autosave'] = {
        "pig_script": request.POST['pig_script'],
        "python_script": request.POST.get('python_script'),
        "title": request.POST.get("title"),
        "arguments": "\t".join(request.POST.getlist("pigParams"))
    }
    return HttpResponse(json.dumps("Done"))

Пример #6
0
            'runState'] if 'status' in result and 'runState' in result[
                'status'] else None
        if runState == job.TEMPLETON_JOB_RUN_STATE_KILLED:
            job.status = job.JOB_KILLED
        elif runState == job.TEMPLETON_JOB_RUN_STATE_FAILED or (
                completed and exitValue is not None and exitValue != 0):
            job.status = job.JOB_FAILED
    except Exception, ex:
        LOG.debug(unicode(ex))
    job.save()
    if job.email_notification:
        subject = 'Query result'
        body = "Your PIG script '%s' started at %s has been completed.\n\
        You can check result at the following link %s" % (
            job.script.title, job.start_time.strftime('%d.%m.%Y %H:%M'),
            "%s%s" % (get_desktop_uri_prefix(),
                      reverse("query_history_job_detail", args=[job_id])))
        job.script.user.email_user(subject, body)
    return HttpResponse("Done")


def autosave_scripts(request):
    request.session['autosave'] = {
        "pig_script": request.POST['pig_script'],
        "python_script": request.POST.get('python_script'),
        "title": request.POST.get("title"),
        "arguments": "\t".join(request.POST.getlist("pigParams"))
    }
    return HttpResponse(json.dumps("Done"))