Gruntwork in middleware where it belongs

This commit is contained in:
James Barnsley
2018-11-02 21:33:24 +13:00
parent acad6490f5
commit f7faa059ad
6 changed files with 10404 additions and 13656 deletions

View File

@ -580,11 +580,7 @@ class IrisCore(pykka.ThreadingActor):
IrisSystemThread('restart', self.restart_callback).start()
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'restart',
'message': "Restarting"
}
'method': "restart_started"
})
response = {
@ -598,22 +594,12 @@ class IrisCore(pykka.ThreadingActor):
def restart_callback(self, response, error):
if error:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'restart',
'type': 'bad',
'message': error,
'finished': True
}
'method': "restart_error",
'params': error
})
else:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'restart',
'message': "Restart completed",
'finished': True
}
'method': "restart_finished"
})
@ -624,11 +610,7 @@ class IrisCore(pykka.ThreadingActor):
callback = kwargs.get('callback', False)
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'upgrade',
'message': "Upgrade running"
}
'method': "upgrade_started"
})
# Trigger the action
@ -646,23 +628,15 @@ class IrisCore(pykka.ThreadingActor):
def upgrade_callback(self, response, error):
if error:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'upgrade',
'type': 'bad',
'message': error,
'finished': True
}
'method': "upgrade_error",
'params': error
})
else:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'upgrade',
'message': "Upgrade completed",
'finished': True
}
'method': "upgrade_finished",
'params': response
})
self.restart()
##
@ -676,11 +650,7 @@ class IrisCore(pykka.ThreadingActor):
IrisSystemThread('local_scan', self.local_scan_callback).start()
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'local_scan',
'message': "Local scan running"
}
'method': "local_scan_started"
})
response = {
@ -694,22 +664,13 @@ class IrisCore(pykka.ThreadingActor):
def local_scan_callback(self, response, error):
if error:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'local_scan',
'type': 'bad',
'message': error,
'finished': True
}
'method': "local_scan_error",
'params': error
})
else:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'local_scan',
'message': "Local scan completed",
'finished': True
}
'method': "local_scan_finished",
'params': response
})
@ -1143,11 +1104,7 @@ class IrisCore(pykka.ThreadingActor):
callback = kwargs.get('callback', False)
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'test',
'message': 'Running test'
}
'method': "test_started"
})
# Trigger the action
@ -1164,21 +1121,12 @@ class IrisCore(pykka.ThreadingActor):
def test_callback(self, response, error):
if error:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'test',
'type': 'bad',
'message': error,
'finished': True
}
'method': "test_error",
'params': error
})
else:
self.broadcast(data={
'method': "update_process",
'params': {
'key': 'test',
'message': "Test completed",
'finished': True
}
'method': "test_finished",
'params': response
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -98,7 +98,7 @@
// Release details
// These are automatically injected to built HTML
var build = "1541097847";
var build = "1541140401";
var version = "3.29.2";
// Construct the script tag

View File

@ -29,10 +29,13 @@ class IrisSystemThread(Thread):
# Run the actual task (this is the process-blocking instruction)
path = os.path.dirname(__file__)
response = subprocess.check_output(["sudo "+path+"/system.sh "+self.action], shell=True)
output = subprocess.check_output(["sudo "+path+"/system.sh "+self.action], shell=True)
# And then, when complete, return to our callback
if self.callback:
response = {
'output': output
}
self.callback(response, False)

View File

@ -114,13 +114,49 @@ const PusherMiddleware = (function(){
case 'reload':
window.location.reload(true);
break;
case 'update_process':
if (message.params.finished){
store.dispatch(uiActions.processFinished(message.params.key));
store.dispatch(uiActions.createNotification(message.params));
} else {
store.dispatch(uiActions.updateProcess(message.params.key, message.params.message));
}
// Local scan
case 'local_scan_started':
store.dispatch(uiActions.updateProcess('local_scan', 'Scanning local library'));
break;
case 'local_scan_finished':
store.dispatch(uiActions.processFinished('local_scan'));
store.dispatch(uiActions.createNotification({key: 'local_scan', type: 'info', content: 'Local scan finished', description: message.params.output}));
break;
case 'local_scan_error':
store.dispatch(uiActions.processFinished('local_scan'));
store.dispatch(uiActions.createNotification({key: 'local_scan', type: 'bad', content: 'Local scan failed'}));
break;
// Upgrade
case 'upgrade_started':
store.dispatch(uiActions.updateProcess('upgrade', 'Upgrading'));
break;
case 'upgrade_finished':
store.dispatch(uiActions.updateProcess('upgrade', 'Restarting to complete upgrade'));
break;
case 'upgrade_error':
store.dispatch(uiActions.processFinished('upgrade'));
store.dispatch(uiActions.createNotification({type: 'bad', content: 'Upgrade failed'}));
break;
// Restart
case 'restart_started':
store.dispatch(uiActions.processFinished('upgrade'));
store.dispatch(uiActions.createNotification({type: 'info', content: 'Restarting server...'}));
break;
// Upgrade
case 'test_started':
store.dispatch(uiActions.updateProcess('test', 'Running test'));
break;
case 'test_finished':
store.dispatch(uiActions.processFinished('test'));
store.dispatch(uiActions.createNotification({type: 'info', content: 'Test finished', description: message.params.output}));
break;
case 'test_error':
store.dispatch(uiActions.processFinished('test'));
store.dispatch(uiActions.createNotification({type: 'bad', content: 'Test failed'}));
break;
}
}