def initialize_user_preferences(): """Initialize any plugins that were installed via pip. This will parse out all the default preference values into one dictionary for later use in the API. """ manager = StoryboardPluginLoader( namespace='storyboard.plugin.user_preferences') if manager.extensions: manager.map(load_preferences, PREFERENCE_DEFAULTS)
def test_add_new(self): """Add a new plugin to the scheduler.""" CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() mock_plugin = MockPlugin(dict()) mock_plugin_name = mock_plugin.get_name() mock_extensions = [ Extension(mock_plugin_name, None, None, mock_plugin) ] loader = StoryboardPluginLoader.make_test_instance( mock_extensions, namespace='storyboard.plugin.testing' ) test_list = list() loader.map(scheduler.add_plugins, test_list) self.assertTrue(test_list.index(mock_plugin_name) == 0) self.assertIsNotNone(scheduler.SCHEDULER.get_job(mock_plugin_name)) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')
def update_scheduler(): """Update the jobs loaded into the scheduler. This runs every minute to keep track of anything that's since been loaded into our execution hooks. """ global SCHEDULER if not SCHEDULER: LOG.warning("Scheduler does not exist, cannot update it.") return # Load all plugins that are registered and load them into the scheduler. loader = StoryboardPluginLoader(namespace="storyboard.plugin.scheduler") loaded_plugins = [SCHEDULE_MANAGER_ID] if loader.extensions: loader.map(add_plugins, loaded_plugins) # Now manually go through the list of jobs in the scheduler and remove # any that haven't been loaded, since some might have been uninstalled. for job in SCHEDULER.get_jobs(): if job.id not in loaded_plugins: LOG.info('Removing Job: %s' % (job.id,)) SCHEDULER.remove_job(job.id)
def update_scheduler(): """Update the jobs loaded into the scheduler. This runs every minute to keep track of anything that's since been loaded into our execution hooks. """ global SCHEDULER if not SCHEDULER: LOG.warning("Scheduler does not exist, cannot update it.") return # Load all plugins that are registered and load them into the scheduler. loader = StoryboardPluginLoader(namespace="storyboard.plugin.scheduler") loaded_plugins = [SCHEDULE_MANAGER_ID] if loader.extensions: loader.map(add_plugins, loaded_plugins) # Now manually go through the list of jobs in the scheduler and remove # any that haven't been loaded, since some might have been uninstalled. for job in SCHEDULER.get_jobs(): if job.id not in loaded_plugins: LOG.info('Removing Job: %s' % (job.id, )) SCHEDULER.remove_job(job.id)
def test_add_plugins_reschedule(self): """Assert that the test_add_plugins will reschedule existing plugins. """ CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() mock_plugin = MockPlugin(dict()) mock_plugin_name = mock_plugin.get_name() mock_extensions = [ Extension(mock_plugin_name, None, None, mock_plugin) ] loader = StoryboardPluginLoader.make_test_instance( mock_extensions, namespace='storyboard.plugin.testing' ) test_list = list() loader.map(scheduler.add_plugins, test_list) self.assertTrue(test_list.index(mock_plugin_name) == 0) first_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name) first_run_trigger = first_run_job.trigger self.assertEqual(mock_plugin._trigger.run_date, first_run_trigger.run_date) # Update the plugin's interval and re-run new_date = datetime.datetime.now() + datetime.timedelta(days=2) mock_plugin._trigger = DateTrigger(run_date=new_date) test_list = list() loader.map(scheduler.add_plugins, test_list) # make sure the plugin is only loaded once. self.assertTrue(test_list.index(mock_plugin_name) == 0) self.assertEquals(len(test_list), 1) # Get the job. second_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name) second_run_trigger = second_run_job.trigger self.assertNotEqual(second_run_trigger.run_date, first_run_trigger.run_date) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')