예제 #1
0
    def test_after_deadline(self):
        deadline = datetime.now()
        start_date = deadline - timedelta(seconds=50)
        duration = 100

        end_round_date = get_round_ending_time(start_date, duration, deadline)
        self.assertEqual(end_round_date, deadline)
예제 #2
0
    def test_if_no_deadline(self):
        deadline = None
        start_date = datetime.now()
        duration = 100
        expected = start_date + timedelta(seconds=duration)

        end_round_date = get_round_ending_time(start_date, duration, deadline)
        self.assertEqual(end_round_date, expected)
    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)
예제 #4
0
    def test_before_deadline(self):
        deadline = datetime.now()
        start_date = deadline - timedelta(hours=2)
        duration = 100

        expected = start_date + timedelta(seconds=duration)

        end_round_date = get_round_ending_time(start_date, duration, deadline)
        self.assertEqual(end_round_date, expected)
예제 #5
0
    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)