def test_create(self, mock_open, mock_json_dump, mock_load, mock_thread): """ Test creating and shutting down event_scheduler. """ mock_load.return_value = '' mock_open.return_value = mock.MagicMock() emitter = mock.MagicMock() es = EventScheduler(emitter) es.shutdown() self.assertEquals(mock_json_dump.call_args[0][0], {})
def test_create(self, mock_open, mock_json_dump, mock_load, mock_thread): """ Test creating and shutting down event_scheduler. """ mock_load.return_value = '' mock_open.return_value = MagicMock() emitter = MagicMock() es = EventScheduler(emitter) es.shutdown() self.assertEqual(mock_json_dump.call_args[0][0], {})
def _starting_up(): """ Start loading skills. Starts - SkillManager to load/reloading of skills when needed - a timer to check for internet connection - adapt intent service - padatious intent service """ global ws, skill_manager, event_scheduler ws.on('intent_failure', FallbackSkill.make_intent_failure_handler(ws)) # Create the Intent manager, which converts utterances to intents # This is the heart of the voice invoked skill system service = IntentService(ws) PadatiousService(ws, service) event_scheduler = EventScheduler(ws) # Create a thread that monitors the loaded skills, looking for updates skill_manager = SkillManager(ws) skill_manager.daemon = True skill_manager.start() # Wait until skills have been loaded once before starting to check # network connection skill_manager.wait_loaded_priority() check_connection()
def _starting_up(): """ Start loading skills. Starts - reloading of skills when needed - a timer to check for internet connection - a timer for updating skills every hour - adapt intent service - padatious intent service """ global ws, skill_reload_thread, event_scheduler ws.on('intent_failure', FallbackSkill.make_intent_failure_handler(ws)) # Create skill_manager listener and invoke the first time ws.on('skill_manager', skills_manager) ws.on('mycroft.internet.connected', install_default_skills) ws.emit(Message('skill_manager', {})) # Create the Intent manager, which converts utterances to intents # This is the heart of the voice invoked skill system PadatiousService(ws) IntentService(ws) event_scheduler = EventScheduler(ws) # Create a thread that monitors the loaded skills, looking for updates skill_reload_thread = WatchSkills() skill_reload_thread.daemon = True skill_reload_thread.start() # Wait until skills have been loaded once before starting to check # network connection skill_reload_thread.wait_loaded_priority() check_connection()
def test_save(self, mock_open, mock_dump, mock_load, mock_thread): """ Test save functionality. """ mock_load.return_value = '' mock_open.return_value = MagicMock() emitter = MagicMock() es = EventScheduler(emitter) # 900000000000 should be in the future for a long time es.schedule_event('test', 900000000000, None) es.schedule_event('test-repeat', 910000000000, 60) es.check_state() es.shutdown() # Make sure the dump method wasn't called with test-repeat self.assertEqual(mock_dump.call_args[0][0], {'test': [(900000000000, None, {}, None)]})
def test_save(self, mock_open, mock_dump, mock_load, mock_thread): """ Test save functionality. """ mock_load.return_value = '' mock_open.return_value = mock.MagicMock() emitter = mock.MagicMock() es = EventScheduler(emitter) # 900000000000 should be in the future for a long time es.schedule_event('test', 900000000000, None) es.schedule_event('test-repeat', 910000000000, 60) es.check_state() es.shutdown() # Make sure the dump method wasn't called with test-repeat self.assertEquals(mock_dump.call_args[0][0], {'test': [(900000000000, None, {})]})
def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread): """ Test save functionality. """ mock_load.return_value = '' mock_open.return_value = MagicMock() emitter = MagicMock() es = EventScheduler(emitter) # 0 should be in the future for a long time es.schedule_event('test', time.time(), None) es.check_state() self.assertEqual(emitter.emit.call_args[0][0].msg_type, 'test') self.assertEqual(emitter.emit.call_args[0][0].data, {}) es.shutdown()
def main(alive_hook=on_alive, started_hook=on_started, ready_hook=on_ready, error_hook=on_error, stopping_hook=on_stopping, watchdog=None): reset_sigint_handler() # Create PID file, prevent multiple instances of this service mycroft.lock.Lock('skills') config = Configuration.get() # Set the active lang to match the configured one set_default_lang(config.get('lang', 'en-us')) # Set the default timezone to match the configured one set_default_tz() # Connect this process to the Mycroft message bus bus = start_message_bus_client("SKILLS") _register_intent_services(bus) event_scheduler = EventScheduler(bus) callbacks = StatusCallbackMap(on_started=started_hook, on_alive=alive_hook, on_ready=ready_hook, on_error=error_hook, on_stopping=stopping_hook) status = ProcessStatus('skills', bus, callbacks) SkillApi.connect_bus(bus) skill_manager = _initialize_skill_manager(bus, watchdog) status.set_started() _wait_for_internet_connection() if skill_manager is None: skill_manager = _initialize_skill_manager(bus, watchdog) device_primer = DevicePrimer(bus, config) device_primer.prepare_device() skill_manager.start() while not skill_manager.is_alive(): time.sleep(0.1) status.set_alive() while not skill_manager.is_all_loaded(): time.sleep(0.1) status.set_ready() wait_for_exit_signal() status.set_stopping() shutdown(skill_manager, event_scheduler)
def _starting_up(): """ Start loading skills. Starts - SkillManager to load/reloading of skills when needed - a timer to check for internet connection - adapt intent service - padatious intent service """ global bus, skill_manager, event_scheduler, connect_to_mycroft_backend bus.on('intent_failure', FallbackSkill.make_intent_failure_handler(bus)) # Create the Intent manager, which converts utterances to intents # This is the heart of the voice invoked skill system service = IntentService(bus) try: PadatiousService(bus, service) except Exception as e: LOG.exception('Failed to create padatious handlers ' '({})'.format(repr(e))) event_scheduler = EventScheduler(bus) # Create a thread that monitors the loaded skills, looking for updates try: skill_manager = SkillManager(bus) except MsmException: # skill manager couldn't be created, wait for network connection and # retry LOG.info( 'Msm is uninitialized and requires network connection', 'to fetch skill information\n' 'Waiting for network connection...') while not connected(): time.sleep(30) skill_manager = SkillManager(bus) skill_manager.daemon = True # Wait until priority skills have been loaded before checking # network connection # print(skill_manager.msm.repo.get_default_skill_names()) skill_manager.load_priority() skill_manager.start() bus.emit(Message('skill.manager.initialised')) if connect_to_mycroft_backend: check_connection() else: check_connection_without_backend()
def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread): """ Test save functionality. """ mock_load.return_value = '' mock_open.return_value = mock.MagicMock() emitter = mock.MagicMock() es = EventScheduler(emitter) # 0 should be in the future for a long time es.schedule_event('test', time.time(), None) es.check_state() self.assertEquals(emitter.emit.call_args[0][0].type, 'test') self.assertEquals(emitter.emit.call_args[0][0].data, {}) es.shutdown()
def test_add_remove(self, mock_open, mock_json_dump, mock_load, mock_thread): """ Test add an event and then remove it. """ # Thread start is mocked so will not actually run the thread loop mock_load.return_value = '' mock_open.return_value = MagicMock() emitter = MagicMock() es = EventScheduler(emitter) # 900000000000 should be in the future for a long time es.schedule_event('test', 90000000000, None) es.schedule_event('test-2', 90000000000, None) es.check_state() # run one cycle self.assertTrue('test' in es.events) self.assertTrue('test-2' in es.events) es.remove_event('test') es.check_state() # run one cycle self.assertTrue('test' not in es.events) self.assertTrue('test-2' in es.events) es.shutdown()
def test_add_remove(self, mock_open, mock_json_dump, mock_load, mock_thread): """ Test add an event and then remove it. """ # Thread start is mocked so will not actually run the thread loop mock_load.return_value = '' mock_open.return_value = mock.MagicMock() emitter = mock.MagicMock() es = EventScheduler(emitter) # 900000000000 should be in the future for a long time es.schedule_event('test', 90000000000, None) es.schedule_event('test-2', 90000000000, None) es.check_state() # run one cycle self.assertTrue('test' in es.events) self.assertTrue('test-2' in es.events) es.remove_event('test') es.check_state() # run one cycle self.assertTrue('test' not in es.events) self.assertTrue('test-2' in es.events) es.shutdown()