This repository has been archived by the owner on Dec 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* split library refresh from playlist refresh * use some more sane method to schedule refresh
- Loading branch information
Showing
6 changed files
with
127 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ username = | |
password = | ||
deviceid = | ||
all_access = false | ||
refresh_library = 1440 | ||
refresh_playlists = 60 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from threading import Event, Thread | ||
|
||
|
||
class RepeatingTimer(Thread): | ||
def __init__(self, method, interval=0, start_after=0): | ||
Thread.__init__(self) | ||
self._stop_event = Event() | ||
self._interval = interval | ||
self._start_after = start_after | ||
self._method = method | ||
|
||
def run(self): | ||
if self._start_after > 0 and self._stop_event.wait(self._start_after): | ||
# stopped during start_after | ||
return | ||
# call method the first time | ||
self._method() | ||
while self._interval > 0 and not self._stop_event.wait(self._interval): | ||
# wait for interval | ||
# call method over and over again | ||
self._method() | ||
|
||
def cancel(self): | ||
self._stop_event.set() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
|
||
import unittest | ||
|
||
from threading import Event | ||
|
||
from mopidy_gmusic.repeating_timer import RepeatingTimer | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ExtensionTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self._event = Event() | ||
|
||
def _run_by_timer(self): | ||
self._event.set() | ||
logger.debug('Tick.') | ||
|
||
def test_init(self): | ||
timer = RepeatingTimer(self._run_by_timer, 0.5, 0) | ||
timer.start() | ||
self.assertTrue(self._event.wait(1), 'timer was not running') | ||
self._event.clear() | ||
self.assertTrue(self._event.wait(1), 'timer was not running') | ||
timer.cancel() | ||
|
||
def test_stop(self): | ||
timer = RepeatingTimer(self._run_by_timer, 10, 0) | ||
timer.start() | ||
self.assertTrue(timer.isAlive(), 'timer is not running') | ||
timer.cancel() | ||
timer.join(1) | ||
self.assertFalse(timer.isAlive(), 'timer is still alive') | ||
|
||
def test_start_after(self): | ||
timer = RepeatingTimer(self._run_by_timer, 0.5, 10) | ||
timer.start() | ||
self.assertFalse(self._event.wait(1), 'timer was run! wtf?') | ||
timer.cancel() | ||
timer.join(1) | ||
self.assertFalse(self._event.wait(0), 'timer should not have run') |