def create_tasks(self): for domain, connection_id, session_id, current_action_due in self.get_survey_sessions_due_for_action(): if skip_domain(domain): 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 create_tasks(self): for domain, connection_id, session_id, current_action_due in self.get_survey_sessions_due_for_action( ): if skip_domain(domain): 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 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)