Exemple #1
0
def run_bots(session: Session, case_number=None):
    bot_list = make_bots(session_pk=session.pk,
                         case_number=case_number,
                         use_browser_bots=False)
    if session.get_room() is None:
        session.mock_exogenous_data()
    session.save()
    runner = SessionBotRunner(bots=bot_list)
    runner.play()
Exemple #2
0
def run_bots(session_id, case_number=None):
    session = Session.objects_get(id=session_id)
    bot_list = make_bots(session_pk=session.id,
                         case_number=case_number,
                         use_browser_bots=False)
    if session.get_room() is None:
        session.mock_exogenous_data()
    runner = SessionBotRunner(bots=bot_list)
    runner.play()
Exemple #3
0
    async def create_session_then_send_start_link(self, use_browser_bots,
                                                  **session_kwargs):
        try:
            session = otree.session.create_session_traceback_wrapper(
                **session_kwargs)

            if use_browser_bots:
                otree.bots.browser.initialize_session(session_pk=session.id,
                                                      case_number=None)
            # the "elif" is because if it uses browser bots, then exogenous data is mocked
            # as part of run_bots.
            # 2020-07-07: this queries the DB, shouldn't i use database_sync_to_async?
            # i don't get any error
            elif session.is_demo:
                session.mock_exogenous_data()
        except Exception as e:
            if isinstance(e, otree.session.CreateSessionError):
                e = e.__cause__
            traceback_str = ''.join(
                traceback.format_exception(type(e), e, e.__traceback__))
            await self.send_response_to_browser(
                dict(error=f'Failed to create session: {e}',
                     traceback=traceback_str))

            # i used to do "raise" here.
            # if I raise, then in non-demo sessions, the traceback is not displayed
            # as it should be.
            # Instead, there is an error
            # "Server error occurred, check Sentry or the logs"
            # I guess the websocket gets cut off? that's also why my test_traceback test was failing.
            # why did I use raise in the first place?
            # was it just so the traceback would go to the console or Sentry?
            # if we show it in the browser, there's no need to show it anywhere else, right?
            # maybe it was just a fallback in case the TB was truncated?
            # or because the traceback should not be shown outside of DEBUG mode
        else:
            from otree.asgi import reverse

            session_home_view = ('MTurkCreateHIT'
                                 if session.is_mturk else 'SessionStartLinks')

            await self.send_response_to_browser(
                {'session_url': reverse(session_home_view, code=session.code)})
Exemple #4
0
    async def create_session_then_send_start_link(self, use_browser_bots,
                                                  **session_kwargs):

        try:
            session = await database_sync_to_async(otree.session.create_session
                                                   )(**session_kwargs)
            if use_browser_bots:
                await database_sync_to_async(
                    otree.bots.browser.initialize_session
                )(session_pk=session.pk, case_number=None)
            # the "elif" is because if it uses browser bots, then exogenous data is mocked
            # as part of run_bots.
            elif session.is_demo:
                session.mock_exogenous_data()
        except Exception as e:
            error_message = 'Failed to create session: "{}"'.format(e)
            traceback_str = traceback.format_exc()
            await self.send_response_to_browser(
                dict(error=error_message, traceback=traceback_str))
            # i used to do "raise" here.
            # if I raise, then in non-demo sessions, the traceback is not displayed
            # as it should be.
            # Instead, there is an error
            # "Server error occurred, check Sentry or the logs"
            # I guess the websocket gets cut off? that's also why my test_traceback test was failing.
            # why did I use raise in the first place?
            # was it just so the traceback would go to the console or Sentry?
            # if we show it in the browser, there's no need to show it anywhere else, right?
            # maybe it was just a fallback in case the TB was truncated?
        else:
            session_home_view = ('MTurkCreateHIT'
                                 if session.is_mturk else 'SessionStartLinks')

            await self.send_response_to_browser({
                'session_url':
                reverse(session_home_view, args=[session.code])
            })