Esempio n. 1
0
    def _assertTaskStatus(self, task, status):
        """
        Confirm the status of this task
        """

        if task.status != status:
            raise base.TaskInconsistentStatusException(
                "%s status is not %s" % (task, base.status(status)))

        if status == base.TASK_STATUS_RUNNING and \
               task not in self._runningList:
            raise base.TaskInconsistentStatusException(
                'task %s was not found in the running task list' % task)
Esempio n. 2
0
    def _assertTaskStatus(self, task, status):
        """
        Confirm the status of this task
        """

        if task.status != status:
            raise base.TaskInconsistentStatusException(
                "%s status is not %s" %
                (task, base.status(status)))

        if status == base.TASK_STATUS_RUNNING and \
               task not in self._runningList:
                raise base.TaskInconsistentStatusException(
                    'task %s was not found in the running task list' % task)
Esempio n. 3
0
    def _db_deleteTaskFromQueue(self, task):
        """
        """

        if isinstance(task, PeriodicTask):
            # don't let periodic tasks respawn
            task.dontComeBack()
            self._dbi.commit()

        oldStatus = task.getStatus()

        self._logger.info("dequeueing %s from status %s" % \
                          (task, base.status(oldStatus)))

        # it doesn't matter if the task is already running again,
        # get rid of it
        self._db_moveTask(task, oldStatus, base.TASK_STATUS_NONE)
Esempio n. 4
0
    def _db_deleteTaskFromQueue(self, task):
        """
        """

        if isinstance(task, tasks.PeriodicTask):
            # don't let periodic tasks respawn
            task.dontComeBack()
            self._dbi.commit()

        oldStatus = task.getStatus()

        self._logger.info("dequeueing %s from status %s" % \
                          (task, base.status(oldStatus)))

        # it doesn't matter if the task is already running again,
        # get rid of it
        self._db_moveTask(task,
                          oldStatus,
                          base.TASK_STATUS_NONE)
Esempio n. 5
0
    def _db_notifyTaskStatus(self, task, status):
        """
        Called by a task when it's done. If a task doesn't notify us
        after AWOLThresold seconds we assume it went AWOL and
        we notify the admins
        """

        if status == base.TASK_STATUS_FINISHED:
            self._logger.info('Task %s says it has finished...' % task)
        elif status == base.TASK_STATUS_FAILED:
            self._logger.error('Task %s says it has failed..' % task)
        else:
            raise Exception('Impossible task/slave state')

            # clean up the mess
            task.tearDown()

        # task forcefully terminated?
        if task.getStatus() == base.TASK_STATUS_TERMINATED:
            # well, we have a final status already, and the task is
            # by now properly indexed
            self._logger.warning("%s finished after being terminated, with status %s" % (task, base.status(status)))

            # If the task has been left running
            if task in self._schedModule.getRunningList():
                self._schedModule.removeRunningTask(task)
            # We end here!
            return
        # else...

        task.setStatus(status)

        # if it's a periodic task, do some extra things
        if isinstance(task, tasks.PeriodicTask):
            # prepare an "occurrence" object

            occurrence = tasks.TaskOccurrence(task)

            task.addOccurrence(occurrence)

            # if the task is supposed to be run again
            if task.shouldComeBack():

                # reset "ended on"
                task.setEndedOn(None)

                # calculate next occurrence
                task.setNextOccurrence()

                # move the occurrence to the correct place
                self._schedModule.moveTask(task,
                                           base.TASK_STATUS_RUNNING,
                                           status,
                                           occurrence = occurrence,
                                           nocheck = True)

                # do not index the task again
                self._db_addTaskToQueue(task, index = False)

                self._logger.info('Task %s rescheduled for %s' %
                                  (task, task.getStartOn()))

        else:
            # move the task to the correct place
            self._schedModule.moveTask(task,
                                       base.TASK_STATUS_RUNNING,
                                       status,
                                       nocheck = True)
Esempio n. 6
0
 def __str__(self):
     return "[%s:%s|%s]" % (self.typeId, self.id,
                            base.status(self.status))
Esempio n. 7
0
 def setStatus(self, newstatus):
     self.getLogger().info("%s set status %s" % (self, base.status(newstatus)))
     self.status = newstatus
Esempio n. 8
0
    def _db_notifyTaskStatus(self, task, status):
        """
        Called by a task when it's done. If a task doesn't notify us
        after AWOLThresold seconds we assume it went AWOL and
        we notify the admins
        """

        if status == base.TASK_STATUS_FINISHED:
            self._logger.info('Task %s says it has finished...' % task)
        elif status == base.TASK_STATUS_FAILED:
            self._logger.error('Task %s says it has failed..' % task)
        else:
            raise Exception('Impossible task/slave state')

            # clean up the mess
            task.tearDown()

        # task forcefully terminated?
        if task.getStatus() == base.TASK_STATUS_TERMINATED:
            # well, we have a final status already, and the task is
            # by now properly indexed
            self._logger.warning(
                "%s finished after being terminated, with status %s" %
                (task, base.status(status)))

            # If the task has been left running
            if task in self._schedModule.getRunningList():
                self._schedModule.removeRunningTask(task)
            # We end here!
            return
        # else...

        task.setStatus(status)

        # if it's a periodic task, do some extra things
        if isinstance(task, PeriodicTask):
            # prepare an "occurrence" object

            occurrence = TaskOccurrence(task)

            task.addOccurrence(occurrence)

            # if the task is supposed to be run again
            if task.shouldComeBack():

                # reset "ended on"
                task.setEndedOn(None)

                # calculate next occurrence
                task.setNextOccurrence()

                # move the occurrence to the correct place
                self._schedModule.moveTask(task,
                                           base.TASK_STATUS_RUNNING,
                                           status,
                                           occurrence=occurrence,
                                           nocheck=True)

                # do not index the task again
                self._db_addTaskToQueue(task, index=False)

                self._logger.info('Task %s rescheduled for %s' %
                                  (task, task.getStartOn()))

        else:
            # move the task to the correct place
            self._schedModule.moveTask(task,
                                       base.TASK_STATUS_RUNNING,
                                       status,
                                       nocheck=True)