mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 09:42:57 -07:00
Re-factor script timeout code
This commit is contained in:
parent
5f7991665c
commit
008e04d5cf
1 changed files with 8 additions and 9 deletions
|
@ -2935,6 +2935,7 @@ class SCRIPTS(Notifier):
|
||||||
}
|
}
|
||||||
|
|
||||||
self.arg_overrides = ('python2', 'python3', 'python', 'pythonw', 'php', 'ruby', 'perl')
|
self.arg_overrides = ('python2', 'python3', 'python', 'pythonw', 'php', 'ruby', 'perl')
|
||||||
|
self.script_killed = False
|
||||||
|
|
||||||
def list_scripts(self):
|
def list_scripts(self):
|
||||||
scriptdir = self.config['script_folder']
|
scriptdir = self.config['script_folder']
|
||||||
|
@ -2954,12 +2955,6 @@ class SCRIPTS(Notifier):
|
||||||
return scripts
|
return scripts
|
||||||
|
|
||||||
def run_script(self, script):
|
def run_script(self, script):
|
||||||
def kill_script(process):
|
|
||||||
logger.warn(u"Tautulli Notifiers :: Script exceeded timeout limit of %d seconds. "
|
|
||||||
"Script killed." % self.config['timeout'])
|
|
||||||
process.kill()
|
|
||||||
self.script_killed = True
|
|
||||||
|
|
||||||
# Common environment variables
|
# Common environment variables
|
||||||
env = {'PLEX_URL': plexpy.CONFIG.PMS_URL,
|
env = {'PLEX_URL': plexpy.CONFIG.PMS_URL,
|
||||||
'PLEX_TOKEN': plexpy.CONFIG.PMS_TOKEN,
|
'PLEX_TOKEN': plexpy.CONFIG.PMS_TOKEN,
|
||||||
|
@ -2968,8 +2963,6 @@ class SCRIPTS(Notifier):
|
||||||
}
|
}
|
||||||
env.update(os.environ)
|
env.update(os.environ)
|
||||||
|
|
||||||
self.script_killed = False
|
|
||||||
output = error = ''
|
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(script,
|
process = subprocess.Popen(script,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
|
@ -2979,7 +2972,7 @@ class SCRIPTS(Notifier):
|
||||||
env=env)
|
env=env)
|
||||||
|
|
||||||
if self.config['timeout'] > 0:
|
if self.config['timeout'] > 0:
|
||||||
timer = threading.Timer(self.config['timeout'], kill_script, (process,))
|
timer = threading.Timer(self.config['timeout'], self.kill_script, (process,))
|
||||||
else:
|
else:
|
||||||
timer = None
|
timer = None
|
||||||
|
|
||||||
|
@ -3009,6 +3002,12 @@ class SCRIPTS(Notifier):
|
||||||
logger.info(u"Tautulli Notifiers :: Script notification sent.")
|
logger.info(u"Tautulli Notifiers :: Script notification sent.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def kill_script(self, process):
|
||||||
|
process.kill()
|
||||||
|
self.script_killed = True
|
||||||
|
logger.warn(u"Tautulli Notifiers :: Script exceeded timeout limit of %d seconds. "
|
||||||
|
"Script killed." % self.config['timeout'])
|
||||||
|
|
||||||
def agent_notify(self, subject='', body='', action='', **kwargs):
|
def agent_notify(self, subject='', body='', action='', **kwargs):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue