def hold(job, clean_job=False, clean_logs=False, hold_children=True): """Hold the given job make sure its no longer on the cluster. The function takes only jobs that are in active state and takes care of the cancellation of any children. :param job: the job :param clean_logs: if True, the job log files will be deleted :param clean_job: if True, the job results will be removed :param silent: if False, the method will print status messages """ if not job.state in db.STATES_ACTIVE: return False log.info("Holding job: %s-%d", str(job), job.id) set_state(job, db.STATE_HOLD, cleanup=clean_job) db.update_job_states(get_group_jobs(job)) if len(job.pipe_from) == 0: cluster = jip.cluster.get() cluster.cancel(job) if clean_logs: clean(job) if hold_children: # cancel children for child in job.children: hold(child, clean_job=clean_job, clean_logs=clean_logs, hold_children=hold_children) return True
def cancel(job, clean_job=False, clean_logs=False, cluster=None, save=False, cancel_children=True): """Cancel the given job and make sure its no longer on the cluster. The function takes only jobs that are in active state and takes care of the cancellation of any children. :param job: the job :type job: `jip.db.Job` :param clean_logs: if True, the job log files will be deleted :param clean_job: if True, the job results will be removed :param cluster: if not Cluster is specified and this is the parent job in a group, the default cluster is loaded :param save: if True, save job in database after state change :param cancel_children: set this to False to disable canceling children of a given job :returns: True if job was canceled """ if not job.state in db.STATES_ACTIVE and job.state != db.STATE_CANCELED: return False log.info("Canceling job: %s-%d", str(job), job.id) set_state(job, db.STATE_CANCELED, cleanup=clean_job) if save: db.update_job_states(job) # cancel the job on the cluster if this is a parent job if len(job.pipe_from) == 0: cluster = jip.cluster.get() if not cluster else cluster cluster.cancel(job) if clean_logs: clean(job) # cancel children if cancel_children: for child in job.children: cancel(child, clean_job=clean_job, clean_logs=clean_logs, cluster=cluster, save=save, cancel_children=cancel_children) return True
def cancel(job, clean_job=False, clean_logs=False, cluster=None, save=False, cancel_children=True ): """Cancel the given job and make sure its no longer on the cluster. The function takes only jobs that are in active state and takes care of the cancellation of any children. :param job: the job :type job: `jip.db.Job` :param clean_logs: if True, the job log files will be deleted :param clean_job: if True, the job results will be removed :param cluster: if not Cluster is specified and this is the parent job in a group, the default cluster is loaded :param save: if True, save job in database after state change :param cancel_children: set this to False to disable canceling children of a given job :returns: True if job was canceled """ if not job.state in db.STATES_ACTIVE and job.state != db.STATE_CANCELED: return False log.info("Canceling job: %s-%d", str(job), job.id) set_state(job, db.STATE_CANCELED, cleanup=clean_job) if save: db.update_job_states(job) # cancel the job on the cluster if this is a parent job if len(job.pipe_from) == 0: cluster = jip.cluster.get() if not cluster else cluster cluster.cancel(job) if clean_logs: clean(job) # cancel children if cancel_children: for child in job.children: cancel(child, clean_job=clean_job, clean_logs=clean_logs, cluster=cluster, save=save, cancel_children=cancel_children) return True