def cancel(self, ignore_missing: bool = False) -> bool: """Cancel the async job. An async job cannot be cancelled once it is taken out of the queue. :param ignore_missing: Do not raise an exception on missing job. :type ignore_missing: bool :return: True if job was cancelled successfully, False if the job was not found but **ignore_missing** was set to True. :rtype: bool :raise arango.exceptions.AsyncJobCancelError: If cancel fails. """ request = Request(method="put", endpoint=f"/_api/job/{self._id}/cancel") resp = self._conn.send_request(request) if resp.status_code == 200: return True elif resp.error_code == 404: if ignore_missing: return False error_message = f"job {self._id} not found" raise AsyncJobCancelError(resp, request, error_message) else: raise AsyncJobCancelError(resp, request)
def handler(res): if res.status_code == 200: self.update('cancelled') return True elif res.status_code == 404: if ignore_missing: return False raise AsyncJobCancelError(res, 'Job {} missing'.format(self.id)) else: raise AsyncJobCancelError(res)
def cancel(self, ignore_missing=False): """Cancel the async job if it is still pending. :param ignore_missing: ignore missing async jobs :type ignore_missing: bool :returns: ``True`` if the job was cancelled successfully, ``False`` if the job was not found but **ignore_missing** was set to ``True`` :rtype: bool :raises arango.exceptions.AsyncJobCancelError: if the async job cannot be cancelled .. note:: An async job cannot be cancelled once it is taken out of the queue (i.e. started, finished or cancelled). """ res = self._conn.put('/_api/job/{}/cancel'.format(self._id)) if res.status_code == 200: return True elif res.status_code == 404: if ignore_missing: return False raise AsyncJobCancelError(res, 'Job {} missing'.format(self._id)) else: raise AsyncJobCancelError(res)