Coverage for python/lsst/ctrl/bps/cancel.py: 19%
18 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-11 03:00 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-11 03:00 -0700
1# This file is part of ctrl_bps.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22"""API for cancelling runs submitted to a WMS.
23"""
25import logging
27from lsst.utils import doImport
29_LOG = logging.getLogger(__name__)
32def cancel(wms_service, wms_id=None, user=None, require_bps=True, pass_thru=None, is_global=False):
33 """Cancel submitted workflows.
35 Parameters
36 ----------
37 wms_service : `str` or `lsst.ctrl.bps.BaseWmsService`
38 Name of the Workload Management System service class.
39 wms_id : `str`, optional
40 ID or path of job that should be canceled.
41 user : `str`, optional
42 User whose submitted jobs should be canceled.
43 require_bps : `bool`, optional
44 Whether to require given run_id/user to be a bps submitted job.
45 pass_thru : `str`, optional
46 Information to pass through to WMS.
47 is_global : `bool`, optional
48 If set, all available job queues will be checked for jobs to cancel.
49 Defaults to False which means that only a local job queue will be
50 checked.
52 Only applicable in the context of a WMS using distributed job queues
53 (e.g., HTCondor).
54 """
55 _LOG.debug(
56 "Cancel params: wms_id=%s, user=%s, require_bps=%s, pass_thru=%s, is_global=%s",
57 wms_id,
58 user,
59 require_bps,
60 pass_thru,
61 is_global,
62 )
64 if isinstance(wms_service, str):
65 wms_service_class = doImport(wms_service)
66 service = wms_service_class({})
67 else:
68 service = wms_service
70 jobs = service.list_submitted_jobs(wms_id, user, require_bps, pass_thru, is_global)
71 if len(jobs) == 0:
72 print(
73 "No job matches the search criteria. "
74 "Hints: Double check id, and/or use --global to search all job queues."
75 )
76 else:
77 for job_id in sorted(jobs):
78 results = service.cancel(job_id, pass_thru)
79 if results[0]:
80 print(f"Successfully canceled job with id '{job_id}'")
81 else:
82 print(f"Couldn't cancel job with id '{job_id}' ({results[1]})")