def update_status(self, new_status: Enum): """Notifys master about new WorkerStatus. :param new_status: the new worker_status """ if self._msg_lock.acquire(timeout=self._lock_timeout): self._send_to_master({'status': new_status.name}, 'PATCH', self._master_address + '/workers/' + self._id) self._msg_lock.release() else: raise (SynchronizationException( SynchronizationException(Out.BLOCK_TIMEOUT % self._id)))
def status(self, ): """Getter for _task_status, using synchronization to keep status consistent. :raises SynchronizationException: if the timeout to aquire lock was exceeded. """ if self._task_lock.acquire(timeout=self._lock_timeout): status = self._task_status self._task_lock.release() return status else: raise (SynchronizationException(Task.BLOCK_TIMEOUT % (self._worker_name, self._id)))
def set_status_force(self, status): """Setter for _task_status, using synchronization to keep status consistent. Use with caution, error status may be overwritten. :param status: the status to be set to :raises SyncronizationException: if the timeout to aquire lock was exceeded. """ if self._task_lock.acquire(timeout=self._lock_timeout): # no error check here self._task_status = status self._task_lock.release() else: raise (SynchronizationException(Task.BLOCK_TIMEOUT % (self._worker_name, self._id)))
def update_task(self, task): """Notifys master about new TaskStatus. Retrieves all the informations from task and sends them. :param task: the task """ if self._msg_lock.acquire(timeout=self._lock_timeout): taskvalues = self._retrieve_task_values(task) self._send_to_master( taskvalues, 'PATCH', self._master_address + '/jobs/' + str(taskvalues['id'])) self._msg_lock.release() else: raise (SynchronizationException(Out.BLOCK_TIMEOUT % task.get_worker_name()))
def status(self, status: WorkerStatus): """ Setter for _status, using synchronization to keep status consistent. :param status: the status to be set to :raises SynchronizationException: if the timeout to aquire lock was exceeded. """ if self._worker_lock.acquire(timeout=self._lock_timeout): self._status = status self._msg.update_status(new_status=status) self._worker_lock.release() else: raise (SynchronizationException(Worker.BLOCK_TIMEOUT % self._name))
def raise_error(self, task): """Notifies Master about an occured Error in task. Retrieves Information from task and sends it to Master. :param task: the task containing the information """ if self._msg_lock.acquire(timeout=self._lock_timeout): taskvalues = dict() taskvalues["errors"] = list(str(err) for err in task.get_errors()) taskvalues = self._retrieve_task_values(task, taskvalues) self._send_to_master( taskvalues, 'PATCH', self._master_address + '/jobs/' + str(taskvalues['id'])) self._msg_lock.release() else: raise (SynchronizationException(Out.BLOCK_TIMEOUT % task.get_worker_name()))
def status(self, new_status: TaskStatus): """Setter for _task_status, using synchronization to keep status consistent. Does not averwrite error status. :param new_status: the status to be set to :raises SyncronizationException: if the timeout to aquire lock was exceeded. """ if self._task_lock.acquire(timeout=self._lock_timeout): # never overwrite errors! if self._task_status == TaskStatus.ERROR or self._task_status == TaskStatus.EXCEPTION: self._task_lock.release() return else: self._task_status = new_status self._task_lock.release() self.msg_out.update_task(self) else: raise (SynchronizationException(Task.BLOCK_TIMEOUT % (self._worker_name, self._id)))