Skip to content

Commit

Permalink
Allow one to adjust interval settings without restarting.
Browse files Browse the repository at this point in the history
  • Loading branch information
basilfx committed Nov 13, 2014
1 parent 396cbb7 commit ee3ccfa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion data/interfaces/default/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h1 class="clearfix"><i class="fa fa-gear"></i> Settings</h1>
</tr>
<tr>
<div class="configmessage">
<i class="fa fa-info-circle"></i> Web Interface changes require a restart to take effect
<i class="fa fa-info-circle"></i> Web Interface changes require a restart to take effect. Saving settings will restart intervals.
</div>
</tr>
</table>
Expand Down
36 changes: 29 additions & 7 deletions headphones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
PIDFILE = None

SCHED = BackgroundScheduler()
SCHED_LOCK = threading.Lock()

INIT_LOCK = threading.Lock()
_INITIALIZED = False
Expand Down Expand Up @@ -256,14 +257,25 @@ def launch_browser(host, port, root):
logger.error('Could not launch browser: %s', e)


def start():
def initialize_scheduler():
"""
Start the scheduled background tasks. Because this method can be called
multiple times, the old tasks will be first removed.
"""

global started
from headphones import updater, searcher, librarysync, postprocessor, \
torrentfinished

if _INITIALIZED:
with SCHED_LOCK:
# Remove all jobs
count = len(SCHED.get_jobs())

# Start our scheduled background tasks
from headphones import updater, searcher, librarysync, postprocessor, torrentfinished
if count > 0:
logger.debug("Current number of background tasks: %d", count)
SCHED.shutdown()
SCHED.remove_all_jobs()

# Then add all jobs
SCHED.add_job(updater.dbUpdate, trigger=IntervalTrigger(
hours=CONFIG.UPDATE_DB_INTERVAL))
SCHED.add_job(searcher.searchforalbum, trigger=IntervalTrigger(
Expand All @@ -281,11 +293,21 @@ def start():

# Remove Torrent + data if Post Processed and finished Seeding
if CONFIG.TORRENT_REMOVAL_INTERVAL > 0:
SCHED.add_job(torrentfinished.checkTorrentFinished, trigger=IntervalTrigger(
minutes=CONFIG.TORRENT_REMOVAL_INTERVAL))
SCHED.add_job(torrentfinished.checkTorrentFinished,
trigger=IntervalTrigger(
minutes=CONFIG.TORRENT_REMOVAL_INTERVAL))

# Start scheduler
logger.info("(Re-)Scheduling background tasks")
SCHED.start()


def start():

global started

if _INITIALIZED:
initialize_scheduler()
started = True


Expand Down
5 changes: 4 additions & 1 deletion headphones/webserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,10 @@ def configUpdate(self, **kwargs):
# Write the config
headphones.CONFIG.write()

#reconfigure musicbrainz database connection with the new values
# Reconfigure scheduler
headphones.initialize_scheduler()

# Reconfigure musicbrainz database connection with the new values
mb.startmb()

raise cherrypy.HTTPRedirect("config")
Expand Down

0 comments on commit ee3ccfa

Please sign in to comment.