Example #1
0
def cache_retry(config, logger):
    """
    Thread timer for the cache retry logic.

    :param config: config (ConfigParser obj)
    """

    retry = 3600
    logger.info('starting cache_retry thread.')
    user_name = config['lastfm']['user_name']
    password = config['lastfm']['password']
    api_key = config['lastfm']['api_key']
    api_secret = config['lastfm']['api_secret']
    cache_location = config['plex-scrobble']['cache_location']

    while True:
        try:
            cache = ScrobbleCache(api_key,
                                  api_secret,
                                  user_name,
                                  password,
                                  cache_location=cache_location)
        except Exception as e:
            logger.warning('ERROR: {0}, retrying in {1} seconds'.format(
                e, retry))
            time.sleep(retry)
            continue
        # do not retry if cache is empty.
        if cache.length() > 0:
            cache.retry_queue()

        time.sleep(retry)
def cache_retry(config, logger):
    """
    Thread timer for the cache retry logic.

    :param config: config (ConfigParser obj)
    """

    retry = 3600
    logger.info('starting cache_retry thread.')
    user_name = config['lastfm']['user_name']
    password = config['lastfm']['password']
    api_key = config['lastfm']['api_key']
    api_secret = config['lastfm']['api_secret']
    cache_location = config['plex-scrobble']['cache_location']

    while True:
        try:
            cache = ScrobbleCache(api_key, api_secret, user_name, password,
                                  cache_location=cache_location)
        except Exception as e:
            logger.warning('ERROR: {0}, retrying in {1} seconds'.format(e, retry))
            time.sleep(retry)
            continue
        # do not retry if cache is empty.
        if cache.length() > 0:
            cache.retry_queue()

        time.sleep(retry)
Example #3
0
class TestScrobbleCache(unittest.TestCase):
    def setUp(self):
        """ create an empty scrobble_cache object. """
        self.sc = ScrobbleCache(config)

    def tearDown(self):
        """ clean up/remove our temporary cache after test run completes. """

        if os.path.isfile(config.get('plex-scrobble', 'cache_location')):
            remove(config.get('plex-scrobble', 'cache_location'))

    def test_add_record_to_cache(self):
        self.sc.add('artist', 'track', 'album')

        self.assertTrue(self.sc.length() == 1)

    def test_delete_record_from_cache(self):
        for key in self.sc.cache:
            self.sc.remove(key)
        self.assertTrue(self.sc.length() == 0)
class TestScrobbleCache(unittest.TestCase):

    def setUp(self):
        """ create an empty scrobble_cache object. """
        self.sc = ScrobbleCache(config)

    def tearDown(self):
        """ clean up/remove our temporary cache after test run completes. """

        if os.path.isfile(config.get('plex-scrobble',
            'cache_location')):
            remove(config.get('plex-scrobble', 'cache_location'))

    def test_add_record_to_cache(self):
        self.sc.add('artist', 'track', 'album')

        self.assertTrue(self.sc.length() == 1)

    def test_delete_record_from_cache(self):
        for key in self.sc.cache:
            self.sc.remove(key)
        self.assertTrue(self.sc.length() == 0)
class TestScrobbleCache(unittest.TestCase):
    def _clean_file(self):
        """ remove the cache file if already exists. """
        if os.path.isfile(config['plex-scrobble']['cache_location']):
            remove(config['plex-scrobble']['cache_location'])

    def setUp(self):
        """ create an empty scrobble_cache object. """
        user_name = password = api_key = api_secret = config['lastfm'][
            'user_name']
        self.sc = ScrobbleCache(
            api_key,
            api_secret,
            user_name,
            password,
            cache_location=config['plex-scrobble']['cache_location'])
        self.album = six.u('Björk').encode('utf-8')
        self.artist = six.u('CR∑∑KS').encode('utf-8')
        self.title = six.u('deep burnt').encode('utf-8')
        self._clean_file()

    def tearDown(self):
        """ clean up/remove our temporary cache after test run completes. """
        self._clean_file()

    def test_add_record_to_cache(self):
        """ tests the addition of a test item to the cache. """
        self.sc.add(self.artist, self.title, self.album)

        self.assertTrue(self.sc.length() == 1)

    def test_delete_record_from_cache(self):
        """ tests the removal of our test item. """
        for key in self.sc.cache:
            self.sc.remove(key)
        self.assertTrue(self.sc.length() == 0)
Example #6
0
def cache_retry(config):
    """
    Thread timer for the cache retry logic.

    :param config: config (ConfigParser obj)
    """

    while True:
        logger.info('starting cache_retry thread.')
        cache = ScrobbleCache(config)
        # do not retry if cache is empty.
        if cache.length() > 0:
            cache.retry_queue()

        cache.close()
        time.sleep(3600)