def form_handler():
    form = app.bids_form.from_json(request.json)
    form.document = app.context['auction_document']
    current_time = datetime.now(TIMEZONE)
    if form.validate():
        with lock_server(app.context['server_actions']):
            app.bids_handler.add_bid(
                form.document['current_stage'], {
                    'amount': form.data['bid'],
                    'bidder_id': form.data['bidder_id'],
                    'time': current_time.isoformat()
                })
            app.logger.info(
                "Bidder {} with client_id {} placed bid {} in {}".format(
                    form.data['bidder_id'], session['client_id'],
                    form.data['bid'], current_time.isoformat()),
                extra=prepare_extra_journal_fields(request.headers))
            return {'status': 'ok', 'data': form.data}
    else:
        app.logger.info("Bidder {} with client_id {} wants place "
                        "bid {} in {} with errors {}".format(
                            request.json.get('bidder_id', 'None'),
                            session['client_id'],
                            request.json.get('bid', 'None'),
                            current_time.isoformat(), repr(form.errors)),
                        extra=prepare_extra_journal_fields(request.headers))
        return {'status': 'failed', 'errors': form.errors}
예제 #2
0
    def switch_to_next_stage(self):
        request_id = generate_request_id()

        with lock_server(self.context['server_actions']):
            with update_auction_document(self.context,
                                         self.database) as auction_document:
                auction_document["current_stage"] += 1

        LOGGER.info('---------------- Start stage {0} ----------------'.format(
            self.context['auction_document']["current_stage"]),
                    extra={
                        "JOURNAL_REQUEST_ID": request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_START_NEXT_STAGE
                    })
예제 #3
0
    def start_auction(self):
        request_id = generate_request_id()
        self.auction_protocol['timeline']['auction_start'][
            'time'] = datetime.now(TIMEZONE).isoformat()

        LOGGER.info('---------------- Start auction  ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_FIRST_PAUSE
                    })
        self.synchronize_auction_info()
        with utils.lock_server(
                self.context['server_actions']), utils.update_auction_document(
                    self.context, self.database) as auction_document:
            self._prepare_initial_bids(auction_document)
            auction_document["current_stage"] = 0
            LOGGER.info("Switched current stage to {}".format(
                auction_document['current_stage']))