Пример #1
0
    def _mark_completed_and_notify(self, group: Optional[BaseGroup]):
        # if group is not passed, then it's the whole subsession
        # could be 2 people creating the record at the same time
        # in _increment_index_in_pages, so could end up creating 2 records
        # but it's not a problem.

        base_kwargs = dict(page_index=self._index_in_pages, session_id=self._session_pk)

        if self.wait_for_all_groups:
            CompletedSubsessionWaitPage.objects.create(**base_kwargs)
            obj = self.subsession
        elif self.group_by_arrival_time:
            CompletedGBATWaitPage.objects.create(
                **base_kwargs, id_in_subsession=group.id_in_subsession
            )
            obj = group
        else:
            CompletedGroupWaitPage.objects.create(**base_kwargs, group_id=group.id)
            obj = group

        player_values = obj.player_set.values(
            'participant__id_in_session', 'participant__code', 'participant__pk'
        )

        self._mark_page_completions(player_values)

        # this can cause messages to get wrongly enqueued in the botworker
        if otree.common.USE_REDIS and not self.participant.is_browser_bot:
            participant_pks = [p['participant__pk'] for p in player_values]
            # 2016-11-15: we used to only ensure the next page is visited
            # if the next page has a timeout, or if it's a wait page
            # but this is not reliable because next page might be skipped anyway,
            # and we don't know what page will actually be shown next to the user.
            otree.timeout.tasks.ensure_pages_visited.schedule(
                kwargs=dict(
                    participant_pks=participant_pks,
                    base_url=self.request.build_absolute_uri('/'),
                ),
                delay=10,
            )

        if self.group_by_arrival_time:
            channel_utils.sync_group_send_wrapper(
                type='gbat_ready',
                group=channel_utils.gbat_group_name(**base_kwargs),
                event={},
            )
        else:
            if self.wait_for_all_groups:
                channels_group_name = channel_utils.subsession_wait_page_name(
                    **base_kwargs
                )
            else:
                channels_group_name = channel_utils.group_wait_page_name(
                    **base_kwargs, group_id=group.id
                )

            channel_utils.sync_group_send_wrapper(
                type='wait_page_ready', group=channels_group_name, event={}
            )
Пример #2
0
    def _mark_completed_and_notify(self, group: Optional[BaseGroup]):
        # if group is not passed, then it's the whole subsession
        # could be 2 people creating the record at the same time
        # in _increment_index_in_pages, so could end up creating 2 records
        # but it's not a problem.

        base_kwargs = dict(page_index=self._index_in_pages, session_id=self._session_pk)
        Player = self.PlayerClass

        if self.wait_for_all_groups:
            CompletedSubsessionWaitPage.objects_create(**base_kwargs)
        elif self.group_by_arrival_time:
            db.add(
                CompletedGBATWaitPage(
                    **base_kwargs, id_in_subsession=group.id_in_subsession
                )
            )
        else:
            db.add(CompletedGroupWaitPage(**base_kwargs, group_id=group.id))

        participants = self._get_participants_for_this_waitpage()
        self._mark_page_completions(list(participants))
        for pp in participants:
            pp._last_page_timestamp = time.time()

        # this can cause messages to get wrongly enqueued in the botworker
        if otree.common.USE_TIMEOUT_WORKER and not self.participant.is_browser_bot:
            # 2016-11-15: we used to only ensure the next page is visited
            # if the next page has a timeout, or if it's a wait page
            # but this is not reliable because next page might be skipped anyway,
            # and we don't know what page will actually be shown next to the user.
            otree.tasks.ensure_pages_visited(
                participant_pks=[pp.id for pp in participants], delay=10,
            )

        if self.group_by_arrival_time:
            channel_utils.sync_group_send(
                group=channel_utils.gbat_group_name(**base_kwargs),
                data={'status': 'ready'},
            )
        else:
            if self.wait_for_all_groups:
                channels_group_name = channel_utils.subsession_wait_page_name(
                    **base_kwargs
                )
            else:
                channels_group_name = channel_utils.group_wait_page_name(
                    **base_kwargs, group_id=group.id
                )

            channel_utils.sync_group_send(
                group=channels_group_name, data={'status': 'ready'}
            )
Пример #3
0
 def group_name(self, session_pk, page_index, participant_id):
     return channel_utils.subsession_wait_page_name(session_pk, page_index)