def delete_jobs(self, jobs=None, tag=None, complete_days=None, family=None, dryrun=False, product=None): """ delete_jobs will mark the job to be deleted To select jobs by id, pass an array for the *jobs* argument. Elements of the array must be strings of the form ``'J:123'``. Alternatively, pass some combination of the *tag*, *complete_days*, or *family* arguments to select jobs for deletion. These arguments behave as per the :meth:`jobs.list` method. If *dryrun* is True, deletions will be reported but nothing will be modified. Admins are not be able to delete jobs which are not owned by themselves by using the tag, complete_days etc kwargs, instead, they should do that via the *jobs* argument. """ if jobs: #Turn them into job objects if not isinstance(jobs, list): jobs = [jobs] jobs_to_try_to_del = [] for j_id in jobs: job = TaskBase.get_by_t_id(j_id) if not isinstance(job, Job): raise BeakerException('Incorrect task type passed %s' % j_id) if not job.can_delete(identity.current.user): raise BeakerException( "You don't have permission to delete job %s" % j_id) jobs_to_try_to_del.append(job) delete_jobs_kw = dict(jobs=jobs_to_try_to_del) else: # only allow people to delete their own jobs while using these kwargs delete_jobs_kw = dict( query=Job.find_jobs(tag=tag, complete_days=complete_days, family=family, product=product, owner=identity.current.user.user_name)) deleted_jobs = Job.delete_jobs(**delete_jobs_kw) msg = 'Jobs deleted' if dryrun: session.rollback() msg = 'Dryrun only. %s' % (msg) return '%s: %s' % (msg, [j.t_id for j in deleted_jobs])
def delete_jobs(self, jobs=None, tag=None, complete_days=None, family=None, dryrun=False, product=None): """ delete_jobs will mark the job to be deleted To select jobs by id, pass an array for the *jobs* argument. Elements of the array must be strings of the form ``'J:123'``. Alternatively, pass some combination of the *tag*, *complete_days*, or *family* arguments to select jobs for deletion. These arguments behave as per the :meth:`jobs.list` method. If *dryrun* is True, deletions will be reported but nothing will be modified. Admins are not be able to delete jobs which are not owned by themselves by using the tag, complete_days etc kwargs, instead, they should do that via the *jobs* argument. """ if jobs: #Turn them into job objects if not isinstance(jobs,list): jobs = [jobs] jobs_to_try_to_del = [] for j_id in jobs: job = TaskBase.get_by_t_id(j_id) if not isinstance(job,Job): raise BeakerException('Incorrect task type passed %s' % j_id ) if not job.can_delete(identity.current.user): raise BeakerException("You don't have permission to delete job %s" % j_id) jobs_to_try_to_del.append(job) delete_jobs_kw = dict(jobs=jobs_to_try_to_del) else: # only allow people to delete their own jobs while using these kwargs delete_jobs_kw = dict(query=Job.find_jobs(tag=tag, complete_days=complete_days, family=family, product=product, owner=identity.current.user.user_name)) deleted_jobs = Job.delete_jobs(**delete_jobs_kw) msg = 'Jobs deleted' if dryrun: session.rollback() msg = 'Dryrun only. %s' % (msg) return '%s: %s' % (msg, [j.t_id for j in deleted_jobs])
def _delete_job(self, t_id): job = TaskBase.get_by_t_id(t_id) self._check_job_deletability(t_id, job) Job.delete_jobs([job]) return [t_id]