def create_task(self): task_id = 1 with self.tasks_lock: while task_id in self.tasks: task_id += 1 task = Task() task.id_ = task_id task.config_file = os.path.join(self.config.tasks_dir, "%i.xml" % (task_id)) self.tasks[task_id] = task # We do not save the task on purpose, empty tasks are worthless. # The task will be saved to disk as soon as one of its properties is # set. # task.save() logging.info("Created a new empty task with ID '%i'.", task_id) # Do not notify the update_wait_cond, the task is disabled so it # doesn't affect the schedule in any way # with self.update_wait_cond: # self.update_wait_cond.notify_all() return task_id
def create_task(self): task_id = 1 with self.tasks_lock: while task_id in self.tasks: task_id += 1 task = Task() task.id_ = task_id task.config_file = os.path.join( self.config.tasks_dir, "%i.xml" % (task_id) ) self.tasks[task_id] = task # We do not save the task on purpose, empty tasks are worthless. # The task will be saved to disk as soon as one of its properties is # set. # task.save() logging.info("Created new empty task with ID '%i'." % (task_id)) # Do not notify the update_wait_cond, the task is disabled so it # doesn't affect the schedule in any way # with self.update_wait_cond: # self.update_wait_cond.notify_all() return task_id
def load_tasks(self): logging.info("Loading task definitions from '%s'...", self.config.tasks_dir) task_files = os.listdir(self.config.tasks_dir) task_count = 0 for task_file in task_files: if not task_file.endswith(".xml"): logging.warning( "Found '%s' in task definitions directory '%s'. Paths " "not ending with '.xml' are unexpected in the task " "definitions directory ", task_file, self.config.tasks_dir ) continue full_path = os.path.join(self.config.tasks_dir, task_file) if not os.path.isfile(full_path): logging.warning( "Found '%s' in task definitions directory '%s'. This path " "is not a file. Only files are expected in the task " "definitions directory ", full_path, self.config.tasks_dir ) continue id_ = Task.get_task_id_from_filepath(full_path) with self.tasks_lock: if id_ not in self.tasks: self.tasks[id_] = Task() self.tasks[id_].load(full_path) task_count += 1 with self.update_wait_cond: self.update_wait_cond.notify_all() logging.info( "Successfully loaded %i task definitions.", task_count )
def load_tasks(self): logging.info("Loading task definitions from '%s'..." % (self.config.tasks_dir)) task_files = os.listdir(self.config.tasks_dir) task_count = 0 for task_file in task_files: if not task_file.endswith(".xml"): logging.warning( "Found '%s' in task definitions directory '%s'. Paths " "not ending with '.xml' are unexpected in the task " "definitions directory " % (task_file, self.config.tasks_dir) ) continue full_path = os.path.join(self.config.tasks_dir, task_file) if not os.path.isfile(full_path): logging.warning( "Found '%s' in task definitions directory '%s'. This path " "is not a file. Only files are expected in the task " "definitions directory " % (full_path, self.config.tasks_dir) ) continue id_ = Task.get_task_id_from_filepath(full_path) with self.tasks_lock: if id_ not in self.tasks: self.tasks[id_] = Task() self.tasks[id_].load(full_path) task_count += 1 with self.update_wait_cond: self.update_wait_cond.notify_all() logging.info( "Successfully loaded %i task definitions." % (task_count) )