changeset 1252:80a92eb82b7f

server (tasks manager): added a label for default site
author Goffi <goffi@goffi.org>
date Wed, 29 Apr 2020 15:00:54 +0200
parents a1606e2a92eb
children 6d49fae517ba
files libervia/server/tasks/manager.py
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libervia/server/tasks/manager.py	Wed Apr 29 14:54:33 2020 +0200
+++ b/libervia/server/tasks/manager.py	Wed Apr 29 15:00:54 2020 +0200
@@ -29,6 +29,8 @@
 
 log = getLogger(__name__)
 
+DEFAULT_SITE_LABEL = _("default site")
+
 
 class TasksManager:
     """Handle tasks of a Libervia site"""
@@ -93,7 +95,7 @@
                     "A task with the name [{name}] already exists".format(
                         name=task_name))
             log.debug(f"task {task_name} found")
-            module_name = f"{self.site_name}.task.{task_name}"
+            module_name = f"{self.site_name or C.SITE_NAME_DEFAULT}.task.{task_name}"
 
             spec = importlib.util.spec_from_file_location(module_name, task_path)
             task_module = importlib.util.module_from_spec(spec)
@@ -129,7 +131,7 @@
         # now we check if there are tasks specific to this site
         if not self.tasks_dir.is_dir():
             log.debug(_("{name} has no task to launch.").format(
-                name = self.resource.site_name or "default site"))
+                name = self.resource.site_name or DEFAULT_SITE_LABEL))
             return
         else:
             await self.parseTasksDir(self.tasks_dir)
@@ -148,7 +150,7 @@
         task = self.tasks[task_name]
         self._current_task = task_name
         log.info(_('== running task "{task_name}" for {site_name} =='.format(
-            task_name=task_name, site_name=self.site_name)))
+            task_name=task_name, site_name=self.site_name or DEFAULT_SITE_LABEL)))
         os.chdir(self.site_path)
         try:
             await utils.asDeferred(task.start)