def __init__(self, country=None, *args, **kwargs): if not country: raise VisionException('Country is required') if self.ENDPOINT is None: raise VisionException('You must set the ENDPOINT name') logger.info('Synchronizer is {}'.format(self.__class__.__name__)) self.country = country connection.set_tenant(country) logger.info('Country is {}'.format(country.name))
def sync_delta_users(): logger.info('Azure Delta Sync Process started') log = VisionSyncLog.objects.create( country=Country.objects.get(schema_name="public"), handler_name='UserADSyncDelta') try: url = cache.get( AZURE_GRAPH_API_USER_CACHE_KEY, '{}/{}/users/delta?$top={}'.format( settings.AZURE_GRAPH_API_BASE_URL, settings.AZURE_GRAPH_API_VERSION, settings.AZURE_GRAPH_API_PAGE_SIZE ) ) status, delta_link = azure_sync_users(url) cache.set(AZURE_GRAPH_API_USER_CACHE_KEY, delta_link) except Exception as e: log.exception_message = force_text(e) logger.exception(force_text(e)) raise VisionException(*e.args) else: log.total_records = status['processed'] + status['skipped'] log.total_processed = status['processed'] log.successful = True finally: log.save() logger.info('Azure Delta Sync Process finished') return delta_link
def __init__(self, country=None, endpoint=None, object_number=None): if not object_number: super().__init__(country=country, endpoint=endpoint) else: if endpoint is None: raise VisionException('You must set the ENDPOINT name') self.url = '{}/{}/{}'.format(self.URL, endpoint, object_number)
def __init__(self, country=None, *args, **kwargs): filename = kwargs.get('filename', None) if not country: raise VisionException('Country is required') if not filename: raise VisionException('You need provide the path to the file') logger.info('Synchronizer is {}'.format(self.__class__.__name__)) self.filename = filename self.country = country connection.set_tenant(country) logger.info('Country is {}'.format(country.name)) super(FileDataSynchronizer, self).__init__(country, *args, **kwargs)
def sync_users(): log = VisionSyncLog(country=Country.objects.get(schema_name="public"), handler_name='UserADSync') try: sync_users_remote() except Exception as e: log.exception_message = force_text(e) raise VisionException(*e.args) finally: log.save()
def map_users(): log = VisionSyncLog(country=Country.objects.get(schema_name="public"), handler_name='UserSupervisorMapper') try: user_sync = UserMapper() user_sync.map_users() except Exception as e: log.exception_message = force_text(e) raise VisionException(*e.args) finally: log.save()
def __init__(self, country=None, endpoint=None): if endpoint is None: raise VisionException('You must set the ENDPOINT name') separator = '' if self.URL.endswith('/') else '/' self.url = '{}{}{}'.format(self.URL, separator, endpoint) if country and country.name != "Global": self.url += '/{}'.format(country.business_area_code) logger.info('About to get data from {}'.format(self.url))
def _load_records(self): logger.debug(self.url) response = requests.get(self.url, headers={'Content-Type': 'application/json'}, auth=(settings.VISION_USER, settings.VISION_PASSWORD), verify=False) if response.status_code != 200: raise VisionException('Load data failed! Http code: {}'.format( response.status_code)) return self._get_json(response.json())
def __init__(self, country=None, object_number=None): self.object_number = object_number if not object_number: super(MultiModelDataSynchronizer, self).__init__(country=country) else: if self.ENDPOINT is None: raise VisionException('You must set the ENDPOINT name') self.country = country connection.set_tenant(country) logger.info('Country is {}'.format(country.name))
def get(self): response = requests.get(self.url, headers={'Content-Type': 'application/json'}, auth=(settings.VISION_USER, settings.VISION_PASSWORD), verify=False) if response.status_code != 200: raise VisionException('Load data failed! Http code: {}'.format( response.status_code)) json_response = response.json() if json_response == VISION_NO_DATA_MESSAGE: return [] return json_response
def sync(self): """ Performs the database sync :return: """ log = VisionSyncLog(country=self.country, handler_name=self.__class__.__name__) self.preload() loader_kwargs = self._get_kwargs() loader_kwargs.update({ kwarg_name: getattr(self, kwarg_name) for kwarg_name in self.LOADER_EXTRA_KWARGS }) data_getter = self.LOADER_CLASS(**loader_kwargs) try: original_records = data_getter.get() logger.info('{} records returned from get'.format( len(original_records))) converted_records = self._convert_records(original_records) log.total_records = len(converted_records) logger.info('{} records returned from conversion'.format( len(converted_records))) totals = self._save_records(converted_records) except Exception as e: logger.info('sync', exc_info=True) log.exception_message = force_text(e) traceback = sys.exc_info()[2] raise VisionException(force_text(e)).with_traceback(traceback) else: if isinstance(totals, dict): log.total_processed = totals.get('processed', 0) log.details = totals.get('details', '') log.total_records = totals.get('total_records', log.total_records) else: log.total_processed = totals log.successful = True finally: log.save()
def sync_all_users(): logger.info('Azure Complete Sync Process started') log = VisionSyncLog.objects.create(country=Country.objects.get(schema_name="public"), handler_name='UserADSync') try: url = '{}/{}/users?$top={}'.format( settings.AZURE_GRAPH_API_BASE_URL, settings.AZURE_GRAPH_API_VERSION, settings.AZURE_GRAPH_API_PAGE_SIZE ) status, _ = azure_sync_users(url) except Exception as e: log.exception_message = force_text(e) logger.exception(force_text(e)) raise VisionException(*e.args) else: log.total_records = status['processed'] + status['skipped'] log.total_processed = status['processed'] log.successful = status['created'] + status['updated'] finally: log.save() logger.info('Azure Complete Sync Process finished')