def on_exist(self, event=None):
        try:
            if self.zkclient.exists(self._path, watch=self.on_exist):
                data, stat = self.zkclient.get(self._path)
                task = Task.from_json(data)
                self._log.info('Found work to do: {0}'.format(task))
                if task.result == ApplicationState.OK:
                    self._log.debug('Task is already complete: {0}'.format(task))
                    return  # ignore tasks that are already done

                if task.name in SENTINEL_METHODS:
                    if task.target is not None:
                        self.send_work_single(task)
                    else:
                        self.send_work_all(task)
                    self._log.info("Submitted task {0} for {1}"
                                   .format(task.name, task.target))
                else:
                    err = 'Invalid work submitted: {0}'.format(task.name)
                    self._log.warning(err)

                task.result = ApplicationState.OK
                self._log.info(task.to_json())
                self.zkclient.set(self._path, task.to_json())

        except NoNodeError:
            self._log.debug('No Node at {0}'.format(self._path))
Beispiel #2
0
 def clear_task_queue(self):
     self._log.info('Starting, so clearing task queue.')
     if self.zkclient.exists(self._path):
         data, stat = self.zkclient.get(self._path)
         task = Task.from_json(data)
         task.result = CommandType.CANCEL
         self.zkclient.set(self._path, task.to_json())
Beispiel #3
0
 def clear_task_queue(self):
     self._log.info('Starting, so clearing task queue.')
     if self.zkclient.exists(self._path):
         data, stat = self.zkclient.get(self._path)
         task = Task.from_json(data)
         task.result = CommandType.CANCEL
         self.zkclient.set(self._path, task.to_json())
Beispiel #4
0
    def on_exist(self, event=None):
        try:
            if self.zkclient.exists(self._path, watch=self.on_exist):
                data, stat = self.zkclient.get(self._path)
                task = Task.from_json(data)
                self._log.info('Found work to do: {0}'.format(task))
                if task.result == ApplicationState.OK:
                    self._log.debug(
                        'Task is already complete: {0}'.format(task))
                    return  # ignore tasks that are already done

                if task.name in SENTINEL_METHODS:
                    if task.target is not None:
                        self.send_work_single(task)
                    else:
                        self.send_work_all(task)
                    self._log.info("Submitted task {0} for {1}".format(
                        task.name, task.target))
                else:
                    err = 'Invalid work submitted: {0}'.format(task.name)
                    self._log.warning(err)

                task.result = ApplicationState.OK
                self._log.info(task.to_json())
                self.zkclient.set(self._path, task.to_json())

        except NoNodeError:
            self._log.debug('No Node at {0}'.format(self._path))
Beispiel #5
0
    def _on_update(self, event):
        """
        Callback for the data watch on the task node
        :type event: kazoo.protocol.states.WatchedEvent
        """
        try:
            data, stat = self._zoo_keeper.get(event.path)
            task = Task.from_json(data)
            if task.result is not None:
                self._remove(task, event.path)
                self._submit_next(task.host)

            else:
                logging.info('Task result is {0}. Resetting watch'
                             .format(task.result))
                self._zoo_keeper.get(event.path, watch=self._on_update)

        except NoNodeError:
            pass
Beispiel #6
0
    def _on_update(self, event):
        """
        Callback for the data watch on the task node
        :type event: kazoo.protocol.states.WatchedEvent
        """
        try:
            data, stat = self._zoo_keeper.get(event.path)
            task = Task.from_json(data)
            if task.result is None:
                logging.info('Task result is {0}. Resetting watch'.format(
                    task.result))
                self._zoo_keeper.get(event.path, watch=self._on_update)
            elif task.result == CommandType.CANCEL:
                logging.info('Sentinel {0} requested task clear.'.format(
                    task.host))
                self._remove(task, event.path, clear_queue=True)
            else:
                self._remove(task, event.path)
                self._submit_next(task.host)

        except NoNodeError:
            pass