Esempio n. 1
0
 def __init__(self, app, start_thread=True):
     self.app = app
     # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
     # Watching the tool_cache means removing outdated items from the tool_cache.
     # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
     # watches regular tools.
     # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
     # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
     # and will be blind to further changes in these tools.
     self.tool_config_watcher = get_tool_conf_watcher(
         reload_callback=lambda: reload_toolbox(self.app),
         tool_cache=self.app.tool_cache)
     self.data_manager_config_watcher = get_tool_conf_watcher(
         reload_callback=lambda: reload_data_managers(self.app))
     self.tool_data_watcher = get_tool_data_dir_watcher(
         self.app.tool_data_tables, config=self.app.config)
     self.tool_watcher = get_tool_watcher(self, app.config)
     if getattr(self.app, 'is_job_handler', False):
         self.job_rule_watcher = get_watcher(app.config,
                                             'watch_job_rules',
                                             monitor_what_str='job rules')
     else:
         self.job_rule_watcher = get_watcher(app.config, '__invalid__')
     if start_thread:
         self.start()
Esempio n. 2
0
    def __init__(self, app):
        self.app = app
        self.active = False

        # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
        # Watching the tool_cache means removing outdated items from the tool_cache.
        # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
        # watches regular tools.
        # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
        # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
        # and will be blind to further changes in these tools.

        def reload_toolbox():
            save_integrated_tool_panel = False
            try:
                # Run and wait for toolbox reload on the process that watches the config files.
                # The toolbpox reload will update the integrated_tool_panel_file
                self.app.queue_worker.send_local_control_task(
                    'reload_toolbox', get_response=True),
            except Exception:
                save_integrated_tool_panel = True
                log.exception("Exception occured while reloading toolbox")
            self.app.queue_worker.send_control_task(
                'reload_toolbox',
                noop_self=True,
                kwargs={
                    'save_integrated_tool_panel': save_integrated_tool_panel
                }),

        self.tool_config_watcher = get_tool_conf_watcher(
            reload_callback=reload_toolbox,
            tool_cache=self.app.tool_cache,
        )
        self.data_manager_config_watcher = get_tool_conf_watcher(
            reload_callback=lambda: self.app.queue_worker.send_control_task(
                'reload_data_managers'), )
        self.tool_data_watcher = get_watcher(self.app.config,
                                             'watch_tool_data_dir',
                                             monitor_what_str='data tables')
        self.tool_watcher = get_tool_watcher(self, app.config)
        if getattr(self.app, 'is_job_handler', False):
            self.job_rule_watcher = get_watcher(app.config,
                                                'watch_job_rules',
                                                monitor_what_str='job rules')
        else:
            self.job_rule_watcher = get_watcher(app.config, '__invalid__')
        self.core_config_watcher = get_watcher(
            app.config,
            'watch_core_config',
            monitor_what_str='core config file')
        self.tour_watcher = get_watcher(app.config,
                                        'watch_tours',
                                        monitor_what_str='tours')
 def __init__(self, app):
     self.app = app
     # ToolConfWatcher objects will watch the tool_cache if the tool_cache is passed into get_tool_conf_watcher.
     # Watching the tool_cache means removing outdated items from the tool_cache.
     # Only the reload_toolbox callback will re-populate the cache, so we pass the tool_cache only to the ToolConfWatcher that
     # watches regular tools.
     # If there are multiple ToolConfWatcher objects for the same handler or web process a race condition occurs between the two cache_cleanup functions.
     # If the reload_data_managers callback wins, the cache will miss the tools that had been removed from the cache
     # and will be blind to further changes in these tools.
     self.tool_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_toolbox(self.app), tool_cache=self.app.tool_cache)
     self.data_manager_config_watcher = get_tool_conf_watcher(reload_callback=lambda: reload_data_managers(self.app))
     self.tool_data_watcher = get_tool_data_dir_watcher(self.app.tool_data_tables, config=self.app.config)
     self.tool_watcher = get_tool_watcher(self, app.config)
     self.start()
Esempio n. 4
0
def test_watcher():
    with __test_directory() as t:
        tool_path = path.join(t, "test.xml")
        toolbox = Toolbox()
        with open(tool_path, "w") as f:
            f.write("a")
        tool_watcher = watcher.get_tool_watcher(toolbox,
                                                bunch.Bunch(watch_tools=True))
        tool_watcher.start()
        tool_watcher.watch_file(tool_path, "cool_tool")
        time.sleep(2)
        assert not toolbox.was_reloaded("cool_tool")
        with open(tool_path, "w") as f:
            f.write("b")
        wait_for_reload(lambda: toolbox.was_reloaded("cool_tool"))
        tool_watcher.shutdown()
        assert tool_watcher.observer is None
Esempio n. 5
0
def test_watcher():
    if not watcher.can_watch:
        from nose.plugins.skip import SkipTest
        raise SkipTest()

    with __test_directory() as t:
        tool_path = path.join(t, "test.xml")
        toolbox = Toolbox()
        open(tool_path, "w").write("a")
        tool_watcher = watcher.get_tool_watcher(toolbox, bunch.Bunch(
            watch_tools=True
        ))
        tool_watcher.watch_file(tool_path, "cool_tool")
        assert not toolbox.was_reloaded("cool_tool")
        open(tool_path, "w").write("b")
        wait_for_reload(lambda: toolbox.was_reloaded("cool_tool"))
        tool_watcher.shutdown()
        assert not tool_watcher.observer.is_alive()