コード例 #1
0
def log_new_download_job(request, download_job):
    write_to_download_log(
        message="Starting new download job [{}]".format(
            download_job.download_job_id),
        download_job=download_job,
        other_params={"request_addr": get_remote_addr(request)},
    )
コード例 #2
0
    def post(self, request):
        """Push a message to SQS with the validated request JSON"""
        json_request = self.validate_request(request.data)
        ordered_json_request = json.dumps(order_nested_object(json_request))

        # Check if the same request has been called today
        updated_date_timestamp = datetime.datetime.strftime(
            datetime.datetime.utcnow(), '%Y-%m-%d')
        cached_download = DownloadJob.objects.filter(
            json_request=ordered_json_request,
            update_date__gte=updated_date_timestamp).exclude(
                job_status_id=4).values('file_name')
        if cached_download and not settings.IS_LOCAL:
            # By returning the cached files, there should be no duplicates on a daily basis
            cached_filename = cached_download[0]['file_name']
            return self.get_download_response(file_name=cached_filename)

        # Create download name and timestamped name for uniqueness
        download_name = '_'.join(
            VALUE_MAPPINGS[award_level]['download_name']
            for award_level in json_request['award_levels'])
        timestamped_file_name = self.s3_handler.get_timestamped_filename(
            download_name + '.zip')
        download_job = DownloadJob.objects.create(
            job_status_id=JOB_STATUS_DICT['ready'],
            file_name=timestamped_file_name,
            json_request=ordered_json_request)

        write_to_log(message='Starting new download job'.format(
            download_job.download_job_id),
                     download_job=download_job,
                     other_params={'request_addr': get_remote_addr(request)})
        self.process_request(download_job)

        return self.get_download_response(file_name=timestamped_file_name)
コード例 #3
0
    def post(self, request, request_type='award'):
        """Push a message to SQS with the validated request JSON"""
        json_request = (self.validate_award_request(request.data)
                        if request_type == 'award' else
                        self.validate_account_request(request.data))
        json_request['request_type'] = request_type
        ordered_json_request = json.dumps(order_nested_object(json_request))

        # Check if the same request has been called today
        updated_date_timestamp = datetime.datetime.strftime(
            datetime.datetime.utcnow(), '%Y-%m-%d')
        cached_download = DownloadJob.objects. \
            filter(json_request=ordered_json_request, update_date__gte=updated_date_timestamp). \
            exclude(job_status_id=4).values('download_job_id', 'file_name')
        if cached_download and not settings.IS_LOCAL:
            # By returning the cached files, there should be no duplicates on a daily basis
            write_to_log(
                message='Generating file from cached download job ID: {}'.
                format(cached_download[0]['download_job_id']))
            cached_filename = cached_download[0]['file_name']
            return self.get_download_response(file_name=cached_filename)

        # Create download name and timestamped name for uniqueness
        toptier_agency_filter = ToptierAgency.objects.filter(
            toptier_agency_id=json_request.get('filters', {}).get(
                'agency', None)).first()
        download_name = '{}_{}'.format(
            toptier_agency_filter.cgac_code if toptier_agency_filter else
            'all', '_'.join(VALUE_MAPPINGS[award_level]['download_name']
                            for award_level in json_request['download_types']))
        timestamped_file_name = self.s3_handler.get_timestamped_filename(
            download_name + '.zip')

        download_job = DownloadJob.objects.create(
            job_status_id=JOB_STATUS_DICT['ready'],
            file_name=timestamped_file_name,
            json_request=ordered_json_request)

        write_to_log(message='Starting new download job'.format(
            download_job.download_job_id),
                     download_job=download_job,
                     other_params={'request_addr': get_remote_addr(request)})
        self.process_request(download_job)

        return self.get_download_response(file_name=timestamped_file_name)
コード例 #4
0
def log_new_download_job(request, download_job):
    write_to_download_log(
        message='Starting new download job [{}]'.format(download_job.download_job_id),
        download_job=download_job,
        other_params={'request_addr': get_remote_addr(request)}
    )