def end_bid_stage(self, bid):
        request_id = generate_request_id()
        LOGGER.info(
            '---------------- End Bids Stage ----------------',
            extra={"JOURNAL_REQUEST_ID": request_id,
                   "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_BID_STAGE}
        )

        # Cleaning up preplanned jobs
        SCHEDULER.remove_all_jobs()

        # Update auction protocol
        auction_protocol = approve_auction_protocol_info_on_bids_stage(
            self.context['auction_document'], self.context['auction_protocol']
        )
        self.context['auction_protocol'] = auction_protocol

        with utils.update_auction_document(self.context, self.database) as auction_document:
            # Creating new stages
            bid_document = {
                'value': {'amount': bid['amount']},
                'minimalStep': auction_document['minimalStep']
            }

            pause, main_round = utils.prepare_auction_stages(
                utils.convert_datetime(bid['time']),
                bid_document,
                self.context.get('deadline'),
                fast_forward=self.context['worker_defaults'].get('sandbox_mode', False)
            )

            auction_document['stages'].append(pause)
            if main_round:
                auction_document['stages'].append(main_round)

            # Updating current stage
            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}
        )

        # Adding jobs to scheduler
        deadline = self.context.get('deadline')

        if main_round:
            round_start_date = utils.convert_datetime(main_round['start'])
            round_end_date = get_round_ending_time(
                round_start_date, ROUND_DURATION, deadline
            )

            self.job_service.add_pause_job(round_start_date)
            self.job_service.add_ending_main_round_job(round_end_date)
        else:
            self.job_service.add_ending_main_round_job(deadline)
    def end_bid_stage(self, bid):
        request_id = generate_request_id()
        LOGGER.info('---------------- End Bids Stage ----------------',
                    extra={
                        "JOURNAL_REQUEST_ID": request_id,
                        "MESSAGE_ID": AUCTION_WORKER_SERVICE_END_BID_STAGE
                    })

        # Cleaning up preplanned jobs
        SCHEDULER.remove_all_jobs()

        with utils.update_auction_document(self.context,
                                           self.database) as auction_document:
            # Creating new stages
            bid_document = {
                'value': {
                    'amount': bid['amount']
                },
                'minimalStep': auction_document['minimalStep']
            }

            pause, main_round = utils.prepare_auction_stages(
                utils.convert_datetime(bid['time']), bid_document)

            auction_document['stages'].append(pause)
            if main_round:
                auction_document['stages'].append(main_round)

            # Updating current stage
            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
                    })

        # Adding jobs to scheduler
        deadline = set_specific_hour(datetime.now(TIMEZONE), DEADLINE_HOUR)

        if main_round:
            round_start_date = utils.convert_datetime(main_round['start'])
            round_end_date = get_round_ending_time(round_start_date,
                                                   ROUND_DURATION, deadline)

            self.job_service.add_pause_job(round_start_date)
            self.job_service.add_ending_main_round_job(round_end_date)
        else:
            self.job_service.add_ending_main_round_job(deadline)
示例#3
0
    def schedule_auction(self):
        self.context['auction_document'] = self.database.get_auction_document(
            self.context['auction_doc_id'])
        with utils.update_auction_document(self.context,
                                           self.database) as auction_document:
            if self.debug:
                LOGGER.info("Get _auction_data from auction_document")
                self._auction_data = auction_document.get(
                    'test_auction_data', {})
            self.synchronize_auction_info()
            self.context['auction_data'] = deepcopy(self._auction_data)
            self.context['bidders_data'] = deepcopy(self.bidders_data)
            self.context['bids_mapping'] = deepcopy(self.bids_mapping)
            self.auction_protocol = utils.prepare_auction_protocol(
                self.context)
            self.context['auction_protocol'] = deepcopy(self.auction_protocol)

        if self.context['auction_document'].get(
                'submissionMethodDetails') == 'quick':
            utils.set_relative_deadline(self.context, self.startDate,
                                        SANDBOX_AUCTION_DURATION)
        else:
            utils.set_absolute_deadline(self.context, self.startDate)

        # Add job that starts auction server
        SCHEDULER.add_job(
            self.start_auction,
            'date',
            run_date=utils.convert_datetime(
                self.context['auction_document']['stages'][0]['start']),
            name="Start of Auction",
            id="auction:start")

        # Add job that switch current_stage to round stage
        start = utils.convert_datetime(
            self.context['auction_document']['stages'][1]['start'])
        self.job_service.add_pause_job(start)

        # Add job that end auction
        start = utils.convert_datetime(
            self.context['auction_document']['stages'][1]
            ['start']) + timedelta(seconds=ROUND_DURATION)
        self.job_service.add_ending_main_round_job(start)

        self.server = run_server(
            self,
            None,  # TODO: add mapping expire
            LOGGER)
        self.context['server'] = self.server
示例#4
0
    def schedule_auction(self):
        self.context['auction_document'] = self.database.get_auction_document(
            self.context['auction_doc_id'])
        with utils.update_auction_document(self.context,
                                           self.database) as auction_document:
            if self.debug:
                LOGGER.info("Get _auction_data from auction_document")
                self._auction_data = auction_document.get(
                    'test_auction_data', {})
            self.synchronize_auction_info()
            self.audit = utils.prepare_audit()
            self.context['audit'] = deepcopy(self.audit)
            self.context['auction_data'] = deepcopy(self._auction_data)
            self.context['bidders_data'] = deepcopy(self.bidders_data)
            self.context['bids_mapping'] = deepcopy(self.bids_mapping)

        # Add job that starts auction server
        SCHEDULER.add_job(
            self.start_auction,
            'date',
            run_date=utils.convert_datetime(
                self.context['auction_document']['stages'][0]['start']),
            name="Start of Auction",
            id="auction:start")

        # Add job that switch current_stage to round stage
        start = utils.convert_datetime(
            self.context['auction_document']['stages'][1]['start'])
        self.job_service.add_pause_job(start)

        # Add job that end auction
        start = utils.convert_datetime(
            self.context['auction_document']['stages'][1]
            ['start']) + timedelta(seconds=ROUND_DURATION)
        self.job_service.add_ending_main_round_job(start)

        self.server = run_server(
            self,
            None,  # TODO: add mapping expire
            LOGGER)
        self.context['server'] = self.server
示例#5
0
    def _set_auction_data(self, prepare=False):
        # Get auction from api and set it to _auction_data
        request_id = generate_request_id()
        if prepare:
            self._auction_data = self.datasource.get_data()
        else:
            self._auction_data = {'data': {}}

        auction_data = self.datasource.get_data(public=False)

        if auction_data:
            self._auction_data['data'].update(auction_data['data'])
            self.startDate = utils.convert_datetime(
                self._auction_data['data']['auctionPeriod']['startDate'])
            del auction_data
        else:
            auction_document = self.database.get_auction_document(
                self.context['auction_doc_id'])
            if auction_document:
                auction_document["current_stage"] = -100
                self.database.save_auction_document(
                    auction_document, self.context['auction_doc_id'])
                LOGGER.warning("Cancel auction: {}".format(
                    self.context['auction_doc_id']),
                               extra={
                                   "JOURNAL_REQUEST_ID": request_id,
                                   "MESSAGE_ID":
                                   AUCTION_WORKER_API_AUCTION_CANCEL
                               })
            else:
                LOGGER.error("Auction {} not exists".format(
                    self.context['auction_doc_id']),
                             extra={
                                 "JOURNAL_REQUEST_ID": request_id,
                                 "MESSAGE_ID":
                                 AUCTION_WORKER_API_AUCTION_NOT_EXIST
                             })
                self._end_auction_event.set()
                sys.exit(1)
示例#6
0
 def _set_start_date(self):
     self.startDate = utils.convert_datetime(self._auction_data['data'].get(
         'auctionPeriod', {}).get('startDate', ''))
示例#7
0
 def _set_start_date(self):
     self.startDate = utils.convert_datetime(self._auction_data['data'].get(
         'auctionPeriod', {}).get('startDate', ''))
     self.deadline_time = datetime(self.startDate.year,
                                   self.startDate.month, self.startDate.day,
                                   DEADLINE_HOUR)