Beispiel #1
0
def _get_job_status(job_id, report_name):
    """
    Continuously polled for updates by the user client, until the notebook has completed execution (or errored).
    """
    job_result = _get_job_results(job_id,
                                  report_name,
                                  get_serializer(),
                                  ignore_cache=True)
    if job_result is None:
        return {"status": "Job not found. Did you use an old job ID?"}
    if job_result.status in (JobStatus.DONE, JobStatus.ERROR,
                             JobStatus.TIMEOUT, JobStatus.CANCELLED):
        response = {
            "status":
            job_result.status.value,
            "results_url":
            url_for("serve_results_bp.task_results",
                    report_name=report_name,
                    job_id=job_id),
        }
    else:
        response = {
            "status": job_result.status.value,
            "run_output": "\n".join(job_result.stdout)
        }
    return response
Beispiel #2
0
def task_results(job_id, report_name):
    """
    Renders the full results page for a given report_name/job_id combination. Most usually accessed from the main page.

    :param job_id: The UUID of the report which we are accessing.
    :param report_name: The name of the report

    :return: The HTML rendering of the results page for a given report_name/job_id combo.
    """
    report_name = convert_report_name_url_to_path(report_name)
    result = _get_job_results(job_id, report_name, get_serializer(), ignore_cache=True)
    return _render_results(job_id, report_name, result)
Beispiel #3
0
def task_results_html(job_id, report_name):
    """
    Returns the HTML render of the .ipynb output of notebook execution. In the webapp this is rendered within an \
    iframe. In this method, we either:

    - present the HTML results, if the job has finished
    - present the error, if the job has failed
    - present the user with some info detailing the progress of the job, if it is still running.

    :param job_id: The UUID of the report which we are accessing.
    :param report_name: The name of the report

    :return: The HTML rendering of the .ipynb for the given report_name & job_id.
    """
    return _process_result_or_abort(_get_job_results(job_id, report_name, get_serializer()))
Beispiel #4
0
def task_result_resources_html(job_id, resource, report_name):
    """
    Returns resources, such as stylesheets and images, which are requested by the HTML rendering of the .ipynb.

    :param report_name: The name of the report.
    :param resource: The relative path to the resource, as saved on disk during execution and saved into storage.
    :param job_id: The UUID of the report.

    :return: A download of the data as requested. 404s if not found.
    """
    result = _get_job_results(job_id, report_name, get_serializer())
    if isinstance(result, NotebookResultComplete):
        html_resources = result.raw_html_resources
        resource_path = os.path.join(get_resources_dir(job_id), resource)
        if resource_path in html_resources.get("outputs", {}):
            return html_resources["outputs"][resource_path]
    abort(404)
Beispiel #5
0
def download_pdf_result(job_id, report_name):
    """
    Allows a user to download the PDF output from storage.

    :param report_name: The name of the report.
    :param job_id: The UUID of the report.

    :return: A download of the PDF as requested. 404s if not found.
    """
    result = _get_job_results(job_id, report_name, get_serializer())
    if isinstance(result, NotebookResultComplete):
        return Response(
            result.pdf,
            mimetype="application/pdf",
            headers={"Content-Disposition": "attachment;filename={}".format(_pdf_filename(job_id))},
        )
    else:
        abort(404)