def create_jobs_for_teams()

in ees_microsoft_teams/deletion_command.py [0:0]


    def create_jobs_for_teams(self, thread_count, start_time, end_time, queue):
        """Creates jobs for deleting the teams and its children objects
        :param thread_count: Thread count to make partitions
        :param start_time: Start time for fetching the data
        :param end_time: End time for fetching the data
        :param queue: Shared queue for storing the data
        """
        allowed_objects = ["teams", "channels", "channel_messages", "channel_tabs", "channel_documents"]
        storage_with_collection = self.local_storage.get_documents_from_doc_id_storage("teams")
        sync_ms_teams_obj = SyncMicrosoftTeams("deletion_sync", self.config, self.logger, queue)

        if not any(teams_object in self.config.get_value("object_type_to_index") for teams_object in allowed_objects):
            return

        self.logger.debug("Started deleting the teams and its objects data...")
        microsoft_teams_object = self.microsoft_team_channel_object(self.get_access_token())
        try:
            deleted_data = storage_with_collection.get("delete_keys") or []
            global_keys_documents = storage_with_collection.get("global_keys") or []

            teams = microsoft_teams_object.get_all_teams([])
            teams_partition_list = split_documents_into_equal_chunks(
                teams, thread_count
            )

            job_documents_list = self.create_and_execute_jobs(
                thread_count,
                sync_ms_teams_obj.fetch_channels_for_deletion,
                (microsoft_teams_object,),
                teams_partition_list,
            )

            channels, channel_index_documents = [], []
            for channel_data in job_documents_list:
                channels.extend(channel_data["channels"])
                channel_index_documents.extend(channel_data["channel_documents"])

            live_data = []
            delete_keys_documents = []

            configuration_objects = self.config.get_value("object_type_to_index")
            if "teams" in configuration_objects:
                live_data.extend(teams)
            if "channels" in configuration_objects:
                live_data.extend(channel_index_documents)

            channels_partition_list = split_documents_into_equal_chunks(channels, thread_count)

            if "channel_messages" in configuration_objects:
                channel_messages = self.create_and_execute_jobs(
                    thread_count, sync_ms_teams_obj.fetch_channel_messages_for_deletion,
                    (microsoft_teams_object, start_time, end_time, []),
                    channels_partition_list
                )
                live_data.extend(channel_messages)

            if "channel_tabs" in configuration_objects:
                channel_tabs = self.create_and_execute_jobs(
                    thread_count, sync_ms_teams_obj.fetch_channel_tabs_for_deletion,
                    (microsoft_teams_object, start_time, end_time, []),
                    channels_partition_list
                )
                live_data.extend(channel_tabs)

            if "channel_documents" in configuration_objects:
                channel_documents = self.create_and_execute_jobs(
                    thread_count, sync_ms_teams_obj.fetch_channel_documents_for_deletion,
                    (microsoft_teams_object, start_time, end_time, []),
                    teams_partition_list
                )
                live_data.extend(channel_documents)

            self.remove_deleted_documents_from_global_keys(
                live_data, deleted_data, delete_keys_documents, global_keys_documents, "", ""
            )

            queue.append_to_queue("deletion", list(delete_keys_documents))
            storage_with_collection["global_keys"] = list(global_keys_documents)
            storage_with_collection["delete_keys"] = []
            self.local_storage.update_storage(storage_with_collection, "teams")

        except Exception as exception:
            self.logger.exception(f"Error while deleting the teams or it's objects data. Error: {exception}")
        self.logger.info("Completed deleting of teams and it's objects data to the Workplace Search")