Ejemplo n.º 1
0
    def get_synced_lists(self):
        synced_lists = []

        for synced_list_data in details_table.get_details():
            details_id = synced_list_data._id

            database_data = database_table.find_detail(details_id)
            provider_data = provider_table.find_detail(details_id)
            list_data = lists_table.find_detail(details_id)
            columns_data = columns_table.find_details(details_id)

            if database_data and provider_data and list_data and columns_data:

                driver = self.get_driver(database_data)
                adapter.setup(driver)

                table = database_data.table
                primary_key = adapter.get_primary_key(table)

                last_inserted_id = self._get_last_inserted_id(
                    list_data, table, primary_key)
                columns_dict = self.get_columns(columns_data)

                try:
                    rows_to_be_synced = adapter.get_rows_to_be_inserted(
                        table, columns_dict, primary_key, last_inserted_id)

                    provider_name = self._get_provider(provider_data.provider)

                    synced_lists.append({
                        "id":
                        synced_list_data._id,
                        "name":
                        list_data.name,
                        "last_synced":
                        synced_list_data.last_synced,
                        "provider":
                        provider_name,
                        "database":
                        database_data,
                        "table":
                        table,
                        "rows_to_be_synced":
                        len(rows_to_be_synced)
                    })
                except Exception, err:
                    logging.error(err)
                    continue
Ejemplo n.º 2
0
	def sync(self, details_id):
		database_data = database_table.find_detail(details_id)
		provider_data = provider_table.find_detail(details_id)
		list_data = lists_table.find_detail(details_id)
		columns_data = columns_table.find_details(details_id)

		adapter.setup(self.get_driver(database_data))

		table = database_data.table
		primary_key = adapter.get_primary_key(table)

		columns = self.get_columns(columns_data)

		if primary_key and adapter.is_valid_connection():
			last_inserted_id = self.get_last_id(adapter, table, primary_key, list_data)
			rows_to_be_inserted = adapter.get_rows_to_be_inserted(table, columns, primary_key, last_inserted_id)
			number_of_rows = len(rows_to_be_inserted)

			if self.status("Completed", list_data) and number_of_rows == 0:
				return True

			provider = Provider(provider_data.provider, provider_data.apikey)
			
			row_chunks = self.split_rows(rows_to_be_inserted, 100)
			header_row = tuple(columns.keys())
			
			self.update_status_running(last_inserted_id, 
				number_of_rows,
				details_id)

			last_id = adapter.get_last_inserted_id(table, 
				primary_key, 
				"last")

			self.sync_users_thread(self.sync_users, 
				provider, 
				list_data.id,
				header_row, 
				row_chunks, 
				last_id, 
				details_id,
				columns)

			return True

		return False
Ejemplo n.º 3
0
    def get_synced_lists(self):
        synced_lists = []
        
        for synced_list_data in details_table.get_details():
            details_id = synced_list_data._id

            database_data = database_table.find_detail(details_id)
            provider_data = provider_table.find_detail(details_id)
            list_data = lists_table.find_detail(details_id)
            columns_data = columns_table.find_details(details_id)

            if database_data and provider_data and list_data and columns_data:

                driver = self.get_driver(database_data)
                adapter.setup(driver)

                table = database_data.table
                primary_key = adapter.get_primary_key(table)

                last_inserted_id = self._get_last_inserted_id(list_data, table, primary_key)
                columns_dict = self.get_columns(columns_data)

                try:
                    rows_to_be_synced = adapter.get_rows_to_be_inserted(table, columns_dict, primary_key, last_inserted_id)
                    
                    provider_name = self._get_provider(provider_data.provider) 
                    
                    synced_lists.append({
                        "id": synced_list_data._id,
                        "name": list_data.name,
                        "last_synced": synced_list_data.last_synced,
                        "provider": provider_name,
                        "database": database_data,
                        "table": table,
                        "rows_to_be_synced": len(rows_to_be_synced)
                    })
                except Exception, err:
                    logging.error(err)
                    continue