Delete all jobs and attachments
(self, cond=None)
| 460 | raise OperationFailure(e) |
| 461 | |
| 462 | def delete_all(self, cond=None): |
| 463 | """Delete all jobs and attachments""" |
| 464 | if cond is None: |
| 465 | cond = {} |
| 466 | try: |
| 467 | for d in self.jobs.find(filter=cond, projection=["_id", "_attachments"]): |
| 468 | logger.info("deleting job %s" % d["_id"]) |
| 469 | for name, file_id in d.get("_attachments", []): |
| 470 | try: |
| 471 | self.gfs.delete(file_id) |
| 472 | except gridfs.errors.NoFile: |
| 473 | logger.error(f"failed to remove attachment {name}:{file_id}") |
| 474 | self.jobs.remove(d) |
| 475 | except pymongo.errors.OperationFailure as e: |
| 476 | # -- translate pymongo error class into hyperopt error class |
| 477 | # see insert() code for rationale. |
| 478 | raise OperationFailure(e) |
| 479 | |
| 480 | def delete_all_error_jobs(self): |
| 481 | return self.delete_all(cond={"state": JOB_STATE_ERROR}) |
no test coverage detected