Example #1
0
    def end_auction(self):
        LOGGER.info('---------------- End auction ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": self.request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_AUCTION
                    })
        LOGGER.debug("Stop server",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        if self.server:
            self.server.stop()
        delete_mapping(self.worker_defaults, self.auction_doc_id)

        LOGGER.debug("Clear mapping",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})

        self.auction_document["current_stage"] = (
            len(self.auction_document["stages"]) - 1)
        self.auction_document['current_phase'] = END
        LOGGER.debug(' '.join(('Document in end_stage: \n',
                               yaml_dump(dict(self.auction_document)))),
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        self.approve_audit_info_on_announcement()
        LOGGER.info('Audit data: \n {}'.format(yaml_dump(self.audit)),
                    extra={"JOURNAL_REQUEST_ID": self.request_id})
        if self.put_auction_data():
            self.save_auction_document()
        LOGGER.debug("Fire 'stop auction worker' event",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})

        self._end_auction_event.set()
    def end_auction(self):
        request_id = generate_request_id()
        LOGGER.info('---------------- End auction ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_AUCTION
                    })

        LOGGER.debug("Stop server", extra={"JOURNAL_REQUEST_ID": request_id})
        if self.context.get('server'):
            self.context['server'].stop()

        delete_mapping(self.context['worker_defaults'],
                       self.context['auction_doc_id'])
        LOGGER.debug("Clear mapping", extra={"JOURNAL_REQUEST_ID": request_id})

        stage = {
            'start': datetime.now(TIMEZONE).isoformat(),
            'type': PREANNOUNCEMENT,
        }
        with update_auction_document(self.context,
                                     self.database) as auction_document:
            auction_document["stages"].append(stage)
            auction_document["current_stage"] = len(
                auction_document["stages"]) - 1

        auction_protocol = approve_auction_protocol_info_on_announcement(
            self.context['auction_document'], self.context['auction_protocol'])
        self.context['auction_protocol'] = auction_protocol
        LOGGER.info('Audit data: \n {}'.format(
            yaml_dump(self.context['auction_protocol'])),
                    extra={"JOURNAL_REQUEST_ID": request_id})
        LOGGER.info(self.context['auction_protocol'])

        result = self.datasource.update_source_object(
            self.context['auction_data'], self.context['auction_document'],
            self.context['auction_protocol'])
        if result and isinstance(result, dict):
            self.context['auction_document'] = result

        auction_end = datetime.now(TIMEZONE)
        stage = prepare_end_stage(auction_end)
        with update_auction_document(self.context,
                                     self.database) as auction_document:
            auction_document["stages"].append(stage)
            auction_document["current_stage"] = len(
                auction_document["stages"]) - 1
            auction_document['endDate'] = auction_end.isoformat()

        self.context['end_auction_event'].set()
Example #3
0
    def end_auction(self):
        LOGGER.info('---------------- End auction ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": self.request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_AUCTION
                    })
        LOGGER.debug("Stop server",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        if self.server:
            self.server.stop()
        LOGGER.debug("Clear mapping",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        delete_mapping(self.worker_defaults, self.auction_doc_id)

        start_stage, end_stage = self.get_round_stages(ROUNDS)
        minimal_bids = deepcopy(
            self.auction_document["stages"][start_stage:end_stage])
        minimal_bids = self.filter_bids_keys(
            sorting_by_amount(minimal_bids, reverse=False))
        self.auction_document["results"] = []
        for item in minimal_bids:
            self.auction_document["results"].append(
                prepare_results_stage(**item))
        self.auction_document["current_stage"] = (
            len(self.auction_document["stages"]) - 1)
        LOGGER.debug(' '.join(
            ('Document in end_stage: \n',
             yaml_dump(json.loads(dumps(self.auction_document))))),
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        self.approve_audit_info_on_announcement()
        LOGGER.info('Audit data: \n {}'.format(
            yaml_dump(json.loads(dumps(self.audit)))),
                    extra={"JOURNAL_REQUEST_ID": self.request_id})
        if self.debug:
            LOGGER.debug('Debug: put_auction_data disabled !!!',
                         extra={"JOURNAL_REQUEST_ID": self.request_id})
            sleep(10)
            self.save_auction_document()
        else:
            if self.put_auction_data():
                self.save_auction_document()
        LOGGER.debug("Fire 'stop auction worker' event",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
Example #4
0
    def end_auction(self):
        request_id = generate_request_id()
        LOGGER.info('---------------- End auction ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_AUCTION
                    })

        LOGGER.debug("Stop server", extra={"JOURNAL_REQUEST_ID": request_id})
        if self.context.get('server'):
            self.context['server'].stop()

        delete_mapping(self.context['worker_defaults'],
                       self.context['auction_doc_id'])
        LOGGER.debug("Clear mapping", extra={"JOURNAL_REQUEST_ID": request_id})

        auction_end = datetime.now(TIMEZONE)
        stage = prepare_end_stage(auction_end)
        auction_document = self.context['auction_document']
        auction_document["stages"].append(stage)
        auction_document["current_stage"] = len(
            self.context['auction_document']["stages"]) - 1

        # TODO: work with audit
        LOGGER.info('Audit data: \n {}'.format(yaml_dump(
            self.context['audit'])),
                    extra={"JOURNAL_REQUEST_ID": request_id})
        LOGGER.info(self.context['audit'])

        auction_document['endDate'] = auction_end.isoformat()
        result = self.datasource.update_source_object(
            self.context['auction_data'], auction_document,
            self.context['audit'])
        if result:
            if isinstance(result, dict):
                self.context['auction_document'] = result
            self.database.save_auction_document(
                self.context['auction_document'],
                self.context['auction_doc_id'])

        self.context['end_auction_event'].set()
Example #5
0
    def end_auction(self):
        LOGGER.info('---------------- End auction ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": self.request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_AUCTION
                    })
        LOGGER.debug("Stop server",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        if self.server:
            self.server.stop()
        delete_mapping(self.worker_defaults, self.auction_doc_id)

        LOGGER.debug("Clear mapping",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        try:
            self.auction_document["current_stage"] = (
                len(self.auction_document["stages"]) - 1)
            self.auction_document['current_phase'] = END
            #normalized_document = normalize_document(self.auction_document)
            #LOGGER.info()
            self.approve_audit_info_on_announcement()
            self.audit = normalize_audit(self.audit)
            #LOGGER.debug(' '.join((
            #    'Document in end_stage: \n', yaml_dump(dict(normalized_document))
            #)), extra={"JOURNAL_REQUEST_ID": self.request_id})
            LOGGER.info('Audit data: \n {}'.format(yaml_dump(self.audit)),
                        extra={"JOURNAL_REQUEST_ID": self.request_id})
            LOGGER.info(self.audit)
            self.auction_document['endDate'] = datetime.now(
                tzlocal()).isoformat()
            if self.put_auction_data():
                self.save_auction_document()
        except Exception as e:
            LOGGER.fatal("Error during end auction: {}".format(e))
        LOGGER.debug("Fire 'stop auction worker' event",
                     extra={"JOURNAL_REQUEST_ID": self.request_id})
        self._end_auction_event.set()