示例#1
0
  def _report_results(self, job_details, result_status, exported_data_url=None):
    logger.info('Reporting result of `%s` for %s; %s', result_status, job_details,
                exported_data_url)

    if job_details.get('callback_url'):
      # Post the results to the callback URL.
      client = app.config['HTTPCLIENT']
      result = client.post(job_details['callback_url'], json={
        'export_id': job_details['export_id'],
        'start_time': job_details['start_time'],
        'end_time': job_details['end_time'],
        'namespace': job_details['namespace_name'],
        'repository': job_details['repository_name'],
        'exported_data_url': exported_data_url,
        'status': result_status.value,
      })

      if result.status_code != 200:
        logger.error('Got `%s` status code for callback URL `%s` for export `%s`',
                     result.status_code, job_details['callback_url'],
                     job_details['export_id'])
        raise Exception('Got non-200 for batch logs reporting; retrying later')

    if job_details.get('callback_email'):
      with app.app_context():
        send_logs_exported_email(job_details['callback_email'], job_details['export_id'],
                                 result_status.value, exported_data_url,
                                 EXPORTED_LOGS_EXPIRATION_SECONDS)
示例#2
0
    def _report_results(self,
                        job_details,
                        result_status,
                        exported_data_url=None):
        logger.debug("Reporting result of `%s` for %s; %s", result_status,
                     job_details, exported_data_url)

        if job_details.get("callback_url"):
            # Post the results to the callback URL.
            client = app.config["HTTPCLIENT"]
            result = client.post(
                job_details["callback_url"],
                json={
                    "export_id": job_details["export_id"],
                    "start_time": job_details["start_time"],
                    "end_time": job_details["end_time"],
                    "namespace": job_details["namespace_name"],
                    "repository": job_details["repository_name"],
                    "exported_data_url": exported_data_url,
                    "status": result_status.value,
                },
            )

            if result.status_code != 200:
                logger.error(
                    "Got `%s` status code for callback URL `%s` for export `%s`",
                    result.status_code,
                    job_details["callback_url"],
                    job_details["export_id"],
                )
                raise Exception(
                    "Got non-200 for batch logs reporting; retrying later")

        if job_details.get("callback_email"):
            with app.app_context():
                send_logs_exported_email(
                    job_details["callback_email"],
                    job_details["export_id"],
                    result_status.value,
                    exported_data_url,
                    EXPORTED_LOGS_EXPIRATION_SECONDS,
                )