def setUpClass(cls): super().setUpClass() cls.session = SQLXFormsSession(session_id='abc123', domain='test-domain', user_id='user_id') cls.formplayer_interface = FormplayerInterface(cls.session.session_id, cls.session.domain)
def test_get_single_open_session(self): properties = _arbitrary_session_properties( end_time=None, session_is_open=True, session_type=XFORMS_SESSION_SMS, ) session = SQLXFormsSession(**properties) session.save() (mult, session) = get_single_open_session_or_close_multiple( session.domain, session.connection_id) self.assertEqual(False, mult) [session_back] = SQLXFormsSession.get_all_open_sms_sessions( session.domain, session.connection_id) self.assertEqual(session._id, session_back.couch_id)
def create_tasks(self): survey_sessions_due_for_action = self.get_survey_sessions_due_for_action( ) all_open_session_ids = self.get_open_session_ids() for domain, connection_id, session_id, current_action_due, phone_number in survey_sessions_due_for_action: if skip_domain(domain): continue if toggles.ONE_PHONE_NUMBER_MULTIPLE_CONTACTS.enabled(domain): fake_session = SQLXFormsSession( session_id=session_id, connection_id=connection_id, phone_number=phone_number, ) if not XFormsSessionSynchronization.channel_is_available_for_session( fake_session): running_session_info = XFormsSessionSynchronization.get_running_session_info_for_channel( fake_session.get_channel()) # First confirm the supposedly running session is even open # and if it's not (should be exceedingly rare) release it and act like it wasn't there if running_session_info.session_id \ and running_session_info.session_id not in all_open_session_ids: notify_error( "The supposedly running session was not open and was released. " "No known way for this to happen, so worth investigating.", details={ 'running_session_info': running_session_info }) XFormsSessionSynchronization.clear_stale_channel_claim( fake_session.get_channel()) # This is the 99% case: there's a running session for the channel # so leave this session/action in the queue for later and move on to the next one else: continue enqueue_lock = self.get_enqueue_lock(session_id, current_action_due) if enqueue_lock.acquire(blocking=False): handle_due_survey_action.delay(domain, connection_id, session_id)
def _make_session(**kwargs): properties = _arbitrary_session_properties(**kwargs) session = SQLXFormsSession(**properties) session.save() return session