Merge branch 'refs/heads/develop'
This commit is contained in:
+3
-3
@@ -72,10 +72,11 @@ class Loader(object):
|
|||||||
signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(1))
|
signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(1))
|
||||||
|
|
||||||
from couchpotato.core.event import addEvent
|
from couchpotato.core.event import addEvent
|
||||||
addEvent('app.after_shutdown', self.afterShutdown)
|
addEvent('app.do_shutdown', self.setRestart)
|
||||||
|
|
||||||
def afterShutdown(self, restart):
|
def setRestart(self, restart):
|
||||||
self.do_restart = restart
|
self.do_restart = restart
|
||||||
|
return True
|
||||||
|
|
||||||
def onExit(self, signal, frame):
|
def onExit(self, signal, frame):
|
||||||
from couchpotato.core.event import fireEvent
|
from couchpotato.core.event import fireEvent
|
||||||
@@ -103,7 +104,6 @@ class Loader(object):
|
|||||||
|
|
||||||
# Release log files and shutdown logger
|
# Release log files and shutdown logger
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
time.sleep(3)
|
|
||||||
|
|
||||||
args = [sys.executable] + [os.path.join(base_path, os.path.basename(__file__))] + sys.argv[1:]
|
args = [sys.executable] + [os.path.join(base_path, os.path.basename(__file__))] + sys.argv[1:]
|
||||||
subprocess.Popen(args)
|
subprocess.Popen(args)
|
||||||
|
|||||||
@@ -91,6 +91,10 @@ class ApiHandler(RequestHandler):
|
|||||||
self.write('API call doesn\'t seem to exist')
|
self.write('API call doesn\'t seem to exist')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Create lock if it doesn't exist
|
||||||
|
if route in api_locks and not api_locks.get(route):
|
||||||
|
api_locks[route] = threading.Lock()
|
||||||
|
|
||||||
api_locks[route].acquire()
|
api_locks[route].acquire()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ class Core(Plugin):
|
|||||||
|
|
||||||
self.shutdown_started = True
|
self.shutdown_started = True
|
||||||
|
|
||||||
fireEvent('app.do_shutdown')
|
fireEvent('app.do_shutdown', restart = restart)
|
||||||
log.debug('Every plugin got shutdown event')
|
log.debug('Every plugin got shutdown event')
|
||||||
|
|
||||||
loop = True
|
loop = True
|
||||||
@@ -143,9 +143,11 @@ class Core(Plugin):
|
|||||||
|
|
||||||
log.debug('Safe to shutdown/restart')
|
log.debug('Safe to shutdown/restart')
|
||||||
|
|
||||||
|
loop = IOLoop.current()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not IOLoop.current()._closing:
|
if not loop._closing:
|
||||||
IOLoop.current().stop()
|
loop.stop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -33,9 +33,9 @@ class Scheduler(Plugin):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def doShutdown(self):
|
def doShutdown(self, *args, **kwargs):
|
||||||
self.stop()
|
self.stop()
|
||||||
return super(Scheduler, self).doShutdown()
|
return super(Scheduler, self).doShutdown(*args, **kwargs)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
if self.started:
|
if self.started:
|
||||||
|
|||||||
@@ -142,11 +142,11 @@ class Updater(Plugin):
|
|||||||
'success': success
|
'success': success
|
||||||
}
|
}
|
||||||
|
|
||||||
def doShutdown(self):
|
def doShutdown(self, *args, **kwargs):
|
||||||
if not Env.get('dev'):
|
if not Env.get('dev'):
|
||||||
removePyc(Env.get('app_dir'), show_logs = False)
|
removePyc(Env.get('app_dir'), show_logs = False)
|
||||||
|
|
||||||
return super(Updater, self).doShutdown()
|
return super(Updater, self).doShutdown(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class BaseUpdater(Plugin):
|
class BaseUpdater(Plugin):
|
||||||
|
|||||||
@@ -454,17 +454,20 @@ class MediaPlugin(MediaBase):
|
|||||||
else:
|
else:
|
||||||
move_to_wanted = True
|
move_to_wanted = True
|
||||||
|
|
||||||
profile = db.get('id', m['profile_id'])
|
try:
|
||||||
media_releases = fireEvent('release.for_media', m['_id'], single = True)
|
profile = db.get('id', m['profile_id'])
|
||||||
|
media_releases = fireEvent('release.for_media', m['_id'], single = True)
|
||||||
|
|
||||||
for q_identifier in profile['qualities']:
|
for q_identifier in profile['qualities']:
|
||||||
index = profile['qualities'].index(q_identifier)
|
index = profile['qualities'].index(q_identifier)
|
||||||
|
|
||||||
for release in media_releases:
|
for release in media_releases:
|
||||||
if q_identifier == release['quality'] and (release.get('status') == 'done' and profile['finish'][index]):
|
if q_identifier == release['quality'] and (release.get('status') == 'done' and profile['finish'][index]):
|
||||||
move_to_wanted = False
|
move_to_wanted = False
|
||||||
|
|
||||||
m['status'] = 'active' if move_to_wanted else 'done'
|
m['status'] = 'active' if move_to_wanted else 'done'
|
||||||
|
except RecordNotFound:
|
||||||
|
log.debug('Failed restatus: %s', traceback.format_exc())
|
||||||
|
|
||||||
# Only update when status has changed
|
# Only update when status has changed
|
||||||
if previous_status != m['status']:
|
if previous_status != m['status']:
|
||||||
|
|||||||
@@ -122,9 +122,12 @@ var NotificationBase = new Class({
|
|||||||
startPoll: function(){
|
startPoll: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
if(self.stopped || (self.request && self.request.isRunning()))
|
if(self.stopped)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(self.request && self.request.isRunning())
|
||||||
|
self.request.cancel();
|
||||||
|
|
||||||
self.request = Api.request('nonblock/notification.listener', {
|
self.request = Api.request('nonblock/notification.listener', {
|
||||||
'onSuccess': function(json){
|
'onSuccess': function(json){
|
||||||
self.processData(json, false)
|
self.processData(json, false)
|
||||||
@@ -149,7 +152,7 @@ var NotificationBase = new Class({
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Process data
|
// Process data
|
||||||
if(json){
|
if(json && json.result){
|
||||||
Array.each(json.result, function(result){
|
Array.each(json.result, function(result){
|
||||||
App.trigger(result._t || result.type, [result]);
|
App.trigger(result._t || result.type, [result]);
|
||||||
if(result.message && result.read === undefined && !init)
|
if(result.message && result.read === undefined && !init)
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ class Plugin(object):
|
|||||||
def afterCall(self, handler):
|
def afterCall(self, handler):
|
||||||
self.isRunning('%s.%s' % (self.getName(), handler.__name__), False)
|
self.isRunning('%s.%s' % (self.getName(), handler.__name__), False)
|
||||||
|
|
||||||
def doShutdown(self):
|
def doShutdown(self, *args, **kwargs):
|
||||||
self.shuttingDown(True)
|
self.shuttingDown(True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+12
-6
@@ -277,22 +277,23 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
loop = IOLoop.current()
|
loop = IOLoop.current()
|
||||||
|
|
||||||
# Reload hook
|
# Reload hook
|
||||||
def test():
|
def reload_hook():
|
||||||
fireEvent('app.shutdown')
|
fireEvent('app.shutdown')
|
||||||
add_reload_hook(test)
|
add_reload_hook(reload_hook)
|
||||||
|
|
||||||
# Some logging and fire load event
|
# Some logging and fire load event
|
||||||
try: log.info('Starting server on port %(port)s', config)
|
try: log.info('Starting server on port %(port)s', config)
|
||||||
except: pass
|
except: pass
|
||||||
fireEventAsync('app.load')
|
fireEventAsync('app.load')
|
||||||
|
|
||||||
|
ssl_options = None
|
||||||
if config['ssl_cert'] and config['ssl_key']:
|
if config['ssl_cert'] and config['ssl_key']:
|
||||||
server = HTTPServer(application, no_keep_alive = True, ssl_options = {
|
ssl_options = {
|
||||||
'certfile': config['ssl_cert'],
|
'certfile': config['ssl_cert'],
|
||||||
'keyfile': config['ssl_key'],
|
'keyfile': config['ssl_key'],
|
||||||
})
|
}
|
||||||
else:
|
|
||||||
server = HTTPServer(application, no_keep_alive = True)
|
server = HTTPServer(application, no_keep_alive = True)
|
||||||
|
|
||||||
try_restart = True
|
try_restart = True
|
||||||
restart_tries = 5
|
restart_tries = 5
|
||||||
@@ -301,6 +302,9 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
try:
|
try:
|
||||||
server.listen(config['port'], config['host'])
|
server.listen(config['port'], config['host'])
|
||||||
loop.start()
|
loop.start()
|
||||||
|
server.close_all_connections()
|
||||||
|
server.stop()
|
||||||
|
loop.close(all_fds = True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error('Failed starting: %s', traceback.format_exc())
|
log.error('Failed starting: %s', traceback.format_exc())
|
||||||
try:
|
try:
|
||||||
@@ -314,6 +318,8 @@ def runCouchPotato(options, base_path, args, data_dir = None, log_dir = None, En
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -272,11 +272,18 @@
|
|||||||
|
|
||||||
(function(){
|
(function(){
|
||||||
|
|
||||||
Api.request('app.available', {
|
var onFailure = function(){
|
||||||
'onFailure': function(){
|
self.checkAvailable.delay(1000, self, [delay, onAvailable]);
|
||||||
self.checkAvailable.delay(1000, self, [delay, onAvailable]);
|
self.fireEvent('unload');
|
||||||
self.fireEvent('unload');
|
}
|
||||||
|
|
||||||
|
var request = Api.request('app.available', {
|
||||||
|
'timeout': 2000,
|
||||||
|
'onTimeout': function(){
|
||||||
|
request.cancel();
|
||||||
|
onFailure();
|
||||||
},
|
},
|
||||||
|
'onFailure': onFailure,
|
||||||
'onSuccess': function(){
|
'onSuccess': function(){
|
||||||
if(onAvailable)
|
if(onAvailable)
|
||||||
onAvailable();
|
onAvailable();
|
||||||
|
|||||||
Reference in New Issue
Block a user