Example #1
0
 def __init__(self):
     self.service_manager = ServiceManager()
     ThreadManager.instance().add_thread(
         'ServicesVerifier',
         self.service_manager.verify_services_status,
         sleep_time=2)
     ThreadManager.instance().start_thread('ServicesVerifier')
Example #2
0
 def stop_service(self, service_name):
     """Stops a service on the thread manager"""
     thread_manager = ThreadManager.instance()
     if thread_manager.is_thread_alive(service_name):
         if service_name == 'AudioRetriever':
             self.audio_retriever.stop_audio()
         ThreadManager.instance().stop_thread(service_name)
         print('\nService stopped successfully\n')
     else:
         print('\nCannot stop service that is not running\n')
Example #3
0
 def main_menu(self):
     """Choice for main menu"""
     looping = True
     while looping:
         MenuMessages.instance().print_main_menu()
         option = self.parse_option(input())
         if option == 1:
             self.services_menu()
         elif option == 2:
             looping = False
             ThreadManager.instance().stop_all()
         else:
             print('Invalid option')
Example #4
0
 def start_light_manager(self, show_message=True):
     """Starts the light maanager service"""
     thread_manager = ThreadManager.instance()
     thread_manager.add_thread('LightManager', self.light_manager.rgb_set)
     thread_manager.start_thread('LightManager')
     print('\nStarted light manager successfully\n')
     self.services_running['LightManager'] = True
Example #5
0
 def start_big_query_synchronizer(self, show_message=True):
     thread_manager = ThreadManager.instance()
     thread_manager.add_thread('BigQuerySynchronizer',
                               self.big_query_synchronizer.synchronize,
                               sleep_time=300)
     thread_manager.start_thread('BigQuerySynchronizer')
     print('\nStarted service big query synchronization successfully\n')
     self.services_running['BigQuerySynchronizer'] = True
Example #6
0
 def start_data_processor(self, show_message=True):
     """Starts the data processor service"""
     thread_manager = ThreadManager.instance()
     thread_manager.add_thread('DataProcessor',
                               self.data_processor.convert_data,
                               sleep_time=60)
     thread_manager.start_thread('DataProcessor')
     print('\nStarted data processor successfully\n')
     self.services_running['DataProcessor'] = True
Example #7
0
 def start_audio_retriever(self, show_message=True):
     """Starts the audio retrieving service"""
     thread_manager = ThreadManager.instance()
     if not self.audio_retriever.is_recorder_device_ready():
         if show_message:
             print(
                 '\nCannot start audio retrieving, verify audio devices\n')
         return
     thread_manager.add_thread('AudioRetriever',
                               self.audio_retriever.retrieve_audio)
     thread_manager.start_thread('AudioRetriever')
     print('\nStarted audio retrieving successfully\n')
     self.services_running['AudioRetriever'] = True
Example #8
0
 def start_drive_synchronizer(self, show_message=True):
     thread_manager = ThreadManager.instance()
     self.drive_synchronizer.authenticate()
     if not self.drive_synchronizer._is_authenticated:
         if show_message:
             print(
                 '\nNot authenticated, cannot start drive synchronization\n'
             )
         return
     thread_manager.add_thread('DriveSynchronizer',
                               self.drive_synchronizer.synchronize,
                               sleep_time=300)
     thread_manager.start_thread('DriveSynchronizer')
     print('\nStarted service drive synchronization successfully\n')
     self.services_running['DriveSynchronizer'] = True
Example #9
0
 def start_service(self, service_name):
     """Starts a service on the thread manager"""
     thread_manager = ThreadManager.instance()
     if thread_manager.is_thread_alive(service_name):
         print('Service is already running')
         return
     if service_name == 'AudioRetriever':
         self.start_audio_retriever()
     if service_name == 'DataProcessor':
         self.start_data_processor()
     if service_name == 'LightManager':
         self.start_light_manager()
     if service_name == 'DriveSynchronizer':
         self.start_drive_synchronizer()
     if service.name == 'BigQuerySynchronizer':
         self.start_big_query_synchronizer()
Example #10
0
 def verify_services_status(self):
     """
     Verify the status of the services running in a thread, if one has been stopped
     by an exception it will start it again automatically
     """
     thread_manager = ThreadManager.instance()
     try:
         for key, value in self.services_running.items():
             if value and not thread_manager.stopped_manually(key):
                 if key == 'AudioRetriever':
                     self.start_audio_retriever(show_message=False)
                     logging.info(
                         'Restarting automatically service audio retrieving'
                     )
                 if key == 'DataProcessor':
                     self.start_data_processor(show_message=False)
                     logging.info(
                         'Restarting automatically service data processor')
                 if key == 'LightManager':
                     self.start_light_manager(show_message=False)
                     logging.info(
                         'Restarting automatically service light manager')
                 if key == 'DriveSynchronizer':
                     self.start_drive_synchronizer(show_message=False)
                     logging.info(
                         'Restarting automatically service drive synchronizer'
                     )
                 if key == 'BigQuerySynchronizer':
                     self.start_big_query_synchronizer(show_message=False)
                     logging.info(
                         'Restarting automatically service big query synchronizer'
                     )
     except Exception as error:
         logging.info(
             'Tried to restart a service but a fatal error ocurred ' +
             str(error))
Example #11
0
 def obtain_services_status(self):
     """Obtains and prints the status of services"""
     print('\n', ThreadManager.instance().status(), '\n')