def test_flush(self): """Test requesting, querying and acknowledging a flush.""" uwsgi = get_uwsgi(True) storage = UWSGIImpressionStorage(uwsgi) assert storage.should_flush() is False storage.request_flush() assert storage.should_flush() is True storage.acknowledge_flush() assert storage.should_flush() is False
def uwsgi_report_impressions(user_config): """ Flush impressions task. :param user_config: User-provided configuration. :type user_config: dict """ config = _get_config(user_config) metadata = get_metadata(config) seconds = config['impressionsRefreshRate'] storage = UWSGIImpressionStorage(get_uwsgi()) impressions_sync = ImpressionSynchronizer( ImpressionsAPI( HttpClient(1500, config.get('sdk_url'), config.get('events_url')), config['apikey'], metadata, config['impressionsMode']), storage, config['impressionsBulkSize']) while True: try: impressions_sync.synchronize_impressions() # pylint: disable=protected-access for _ in range(0, seconds): if storage.should_flush(): storage.acknowledge_flush() break time.sleep(1) except Exception: # pylint: disable=broad-except _LOGGER.error('Error posting impressions') _LOGGER.debug('Error: ', exc_info=True)