--- a/borgend/backup.py Sun Feb 04 02:19:26 2018 +0000 +++ b/borgend/backup.py Sun Feb 04 09:38:55 2018 +0000 @@ -34,6 +34,8 @@ QUEUED=3 ACTIVE=4 + def __str__(self): + return _statestring[self] class Errors(IntEnum): OK=0 @@ -57,6 +59,14 @@ Errors.ERRORS: 'errors' } +_statestring={ + State.INACTIVE: 'inactive', + State.PAUSED: 'paused', + State.SCHEDULED: 'scheduled', + State.QUEUED: 'queued', + State.ACTIVE: 'active' +} + class Operation: CREATE='create' PRUNE='prune' @@ -79,6 +89,12 @@ def add_error(self, error): self.errors=self.errors.combine(error) + def name(self): + if 'reason' in self.detail: + return str(self.type) + '.' + self.detail['reason'] + else: + return str(self.type) + class Status(Operation): def __init__(self, backup, op=None): @@ -447,9 +463,8 @@ # Update scheduled time to real starting time to schedule # next run relative to this self.current_operation.start_time=MonotonicTime.now() - self.state=State.ACTIVE # Reset error status when starting a new operation - self.__update_status() + self.__update_status(State.ACTIVE) t_log.start() t_res.start() @@ -577,31 +592,25 @@ if self._pause: self.logger.info("Waiting for resume to be signalled") - self.state=State.PAUSED - self.__update_status() + self.__update_status(State.PAUSED) self._cond.wait() else: if not self.scheduled_operation: op=self.__next_operation_unlocked() if op: - self.logger.info("Scheduling '%s' (detail: %s) on %s [%s]" % - (str(op.type), op.detail or 'none', - op.start_time.isoformat(), - op.start_time.__class__.__name__)) + self.scheduled_operation=op - self.scheduled_operation=op - self.state=State.SCHEDULED - self.__update_status() + self.__update_status(State.SCHEDULED) # Wait under scheduled wait - self.scheduler.wait_until(op.start_time, self._cond, self.backup_name) + eventname=op.name() + '@' + self.backup_name + self.scheduler.wait_until(op.start_time, self._cond, eventname) else: # Nothing scheduled - just wait self.logger.info("Waiting for manual scheduling") - self.state=State.INACTIVE - self.__update_status() + self.__update_status(State.INACTIVE) self._cond.wait() @@ -611,9 +620,9 @@ # available def __main_thread_queue_and_launch(self): if self.scheduled_operation: - self.logger.debug("Queuing") - self.state=State.QUEUED - self.__update_status() + + self.__update_status(State.QUEUED) + res=self.repository.queue_action(self._cond, action=self.__launch_and_wait, name=self.backup_name) @@ -711,7 +720,9 @@ return status, callback - def __update_status(self): + def __update_status(self, state): + self.logger.debug("Entering %s state", str(state)) + self.state=state status, callback = self.__status_unlocked() if callback: #self._cond.release() @@ -755,7 +766,7 @@ def is_paused(self): with self._cond: - paused=self.state==State.PAUSED + paused=(self.state==State.PAUSED) return paused def pause(self):