Improve startup speed by refreshing on a separate thread

This commit is contained in:
JonnyWong16 2020-10-25 13:07:42 -07:00
commit 558023e18e
No known key found for this signature in database
GPG key ID: B1F1F9807184697A
5 changed files with 122 additions and 77 deletions

View file

@ -334,18 +334,6 @@ def initialize(config_file):
logger.error("Unable to write current release to file '%s': %s" %
(release_file, e))
# Get the real PMS urls for SSL and remote access
if CONFIG.PMS_TOKEN and CONFIG.PMS_IP and CONFIG.PMS_PORT:
plextv.get_server_resources()
# Refresh the users list on startup
if CONFIG.PMS_TOKEN and CONFIG.REFRESH_USERS_ON_STARTUP:
users.refresh_users()
# Refresh the libraries list on startup
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN and CONFIG.REFRESH_LIBRARIES_ON_STARTUP:
libraries.refresh_libraries()
# Store the original umask
UMASK = os.umask(0)
os.umask(UMASK)
@ -523,6 +511,9 @@ def start():
global _STARTED
if _INITIALIZED:
# Start refreshes on a separate thread
threading.Thread(target=startup_refresh).start()
global SCHED
SCHED = BackgroundScheduler(timezone=pytz.UTC)
activity_handler.ACTIVITY_SCHED = BackgroundScheduler(timezone=pytz.UTC)
@ -535,12 +526,13 @@ def start():
notification_handler.start_threads(num_threads=CONFIG.NOTIFICATION_THREADS)
notifiers.check_browser_enabled()
# Schedule newsletters
newsletter_handler.NEWSLETTER_SCHED.start()
newsletter_handler.schedule_newsletters()
# Cancel processing exports
exporter.cancel_exports()
if CONFIG.FIRST_RUN_COMPLETE:
activity_pinger.connect_server(log=True, startup=True)
if CONFIG.SYSTEM_ANALYTICS:
global TRACKER
TRACKER = initialize_tracker()
@ -554,13 +546,27 @@ def start():
analytics_event(category='system', action='start')
# Schedule newsletters
newsletter_handler.NEWSLETTER_SCHED.start()
newsletter_handler.schedule_newsletters()
_STARTED = True
def startup_refresh():
# Get the real PMS urls for SSL and remote access
if CONFIG.PMS_TOKEN and CONFIG.PMS_IP and CONFIG.PMS_PORT:
plextv.get_server_resources()
# Connect server after server resource is refreshed
if CONFIG.FIRST_RUN_COMPLETE:
activity_pinger.connect_server(log=True, startup=True)
# Refresh the users list on startup
if CONFIG.PMS_TOKEN and CONFIG.REFRESH_USERS_ON_STARTUP:
users.refresh_users()
# Refresh the libraries list on startup
if CONFIG.PMS_IP and CONFIG.PMS_TOKEN and CONFIG.REFRESH_LIBRARIES_ON_STARTUP:
libraries.refresh_libraries()
def sig_handler(signum=None, frame=None):
if signum is not None:
logger.info("Signal %i caught, saving and exiting...", signum)

View file

@ -122,7 +122,8 @@ def add_live_tv_library(refresh=False):
if result and not refresh or not result and refresh:
return
logger.info("Tautulli Libraries :: Adding Live TV library to the database.")
if not refresh:
logger.info("Tautulli Libraries :: Adding Live TV library to the database.")
section_keys = {'server_id': plexpy.CONFIG.PMS_IDENTIFIER,
'section_id': common.LIVE_TV_SECTION_ID}

View file

@ -6545,6 +6545,31 @@ class WebInterface(object):
return status
@cherrypy.expose
@cherrypy.tools.json_out()
@addtoapi()
def server_status(self, *args, **kwargs):
""" Get the current status of Tautulli's connection to the Plex server.
```
Required parameters:
None
Optional parameters:
None
Returns:
json:
{"result": "success",
"connected": true,
}
```
"""
cherrypy.response.headers['Cache-Control'] = "max-age=0,no-cache,no-store"
status = {'result': 'success', 'connected': plexpy.PLEX_SERVER_UP}
return status
@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth(member_of("admin"))