mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 06:12:54 +00:00 
			
		
		
		
	Extract process managing logic to SupervisorMixin from event handlers
This commit is contained in:
		@@ -1,7 +1,5 @@
 | 
			
		||||
from shutil import copy, rmtree, copytree
 | 
			
		||||
from os.path import splitext
 | 
			
		||||
from contextlib import suppress
 | 
			
		||||
from xmlrpc.client import Fault as SupervisorFault
 | 
			
		||||
 | 
			
		||||
from tfw.util import SupervisorMixin
 | 
			
		||||
from tfw.config import LOGIN_APP_DIR
 | 
			
		||||
@@ -43,19 +41,16 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
 | 
			
		||||
        data = data_json['data']
 | 
			
		||||
        with open(self.file, 'w') as ofile:
 | 
			
		||||
            ofile.write(data['content'])
 | 
			
		||||
        self.supervisor.stopProcess(self.process_name)
 | 
			
		||||
        self.supervisor.startProcess(self.process_name)
 | 
			
		||||
        self.restart_process()
 | 
			
		||||
 | 
			
		||||
    def create_initial_state(self):
 | 
			
		||||
        with suppress(SupervisorFault):
 | 
			
		||||
            self.supervisor.stopProcess(self.process_name)
 | 
			
		||||
        self.stop_process()
 | 
			
		||||
 | 
			
		||||
        rmtree(self.working_directory, ignore_errors=True)
 | 
			
		||||
        copytree('source_code_server/', self.working_directory)
 | 
			
		||||
        file = copy(self.filename, self.working_directory)
 | 
			
		||||
 | 
			
		||||
        self.supervisor.startProcess(self.process_name)
 | 
			
		||||
 | 
			
		||||
        self.start_process()
 | 
			
		||||
        return file
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
 | 
			
		||||
    def setup_terminado_server(self):
 | 
			
		||||
        rmtree(self.working_directory, ignore_errors=True)
 | 
			
		||||
        copytree('terminado_server/', self.working_directory)
 | 
			
		||||
        self.supervisor.startProcess(self.process_name)
 | 
			
		||||
        self.start_process()
 | 
			
		||||
 | 
			
		||||
    def handle_event(self, anchor, data_json):
 | 
			
		||||
        log.debug('TerminadoEventHandler received event for anchor {}'.format(anchor))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user