Esempio n. 1
0
	def find_by_id(self, writer_id: ExternalWriterId) -> Optional[ExternalWriter]:
		external_writer = CacheService.external_writer().get(writer_id)
		if external_writer is not None:
			if external_writer.tenantId != self.principalService.get_tenant_id():
				raise DataKernelException(
					f'External writer[id={writer_id}] not belongs to '
					f'current tenant[id={self.principalService.get_tenant_id()}].')
			register_external_writer(external_writer)
			return external_writer

		storage_service = ExternalWriterStorageService(
			ask_meta_storage(), ask_snowflake_generator(), self.principalService)
		storage_service.begin_transaction()
		try:
			# noinspection PyTypeChecker
			external_writer: ExternalWriter = storage_service.find_by_id(writer_id)
			if external_writer is None:
				return None

			CacheService.external_writer().put(external_writer)
			register_external_writer(external_writer)
			return external_writer
		finally:
			storage_service.close_transaction()
async def clear_all_external_writers_cache(
        principal_service: PrincipalService = Depends(
            get_super_admin_principal)) -> None:
    CacheService.external_writer().clear()