Coverage for python / lsst / ctrl / bps / cancel.py: 16%

17 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-14 23:51 +0000

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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

15# This program is free software: you can redistribute it and/or modify 

16# it under the terms of the GNU General Public License as published by 

17# the Free Software Foundation, either version 3 of the License, or 

18# (at your option) any later version. 

19# 

20# This program is distributed in the hope that it will be useful, 

21# but WITHOUT ANY WARRANTY; without even the implied warranty of 

22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

23# GNU General Public License for more details. 

24# 

25# You should have received a copy of the GNU General Public License 

26# along with this program. If not, see <https://www.gnu.org/licenses/>. 

27 

28"""API for cancelling runs submitted to a WMS.""" 

29 

30import logging 

31 

32from lsst.utils import doImport 

33 

34_LOG = logging.getLogger(__name__) 

35 

36 

37def cancel(wms_service, wms_id=None, user=None, require_bps=True, pass_thru=None, is_global=False): 

38 """Cancel submitted workflows. 

39 

40 Parameters 

41 ---------- 

42 wms_service : `str` or `lsst.ctrl.bps.BaseWmsService` 

43 Name of the Workload Management System service class. 

44 wms_id : `str`, optional 

45 ID or path of job that should be canceled. 

46 user : `str`, optional 

47 User whose submitted jobs should be canceled. 

48 require_bps : `bool`, optional 

49 Whether to require given run_id/user to be a bps submitted job. 

50 pass_thru : `str`, optional 

51 Information to pass through to WMS. 

52 is_global : `bool`, optional 

53 If set, all available job queues will be checked for jobs to cancel. 

54 Defaults to False which means that only a local job queue will be 

55 checked. 

56 

57 Only applicable in the context of a WMS using distributed job queues 

58 (e.g., HTCondor). 

59 """ 

60 _LOG.debug( 

61 "Cancel params: wms_id=%s, user=%s, require_bps=%s, pass_thru=%s, is_global=%s", 

62 wms_id, 

63 user, 

64 require_bps, 

65 pass_thru, 

66 is_global, 

67 ) 

68 

69 if isinstance(wms_service, str): 

70 wms_service_class = doImport(wms_service) 

71 service = wms_service_class({}) 

72 else: 

73 service = wms_service 

74 

75 jobs = service.list_submitted_jobs(wms_id, user, require_bps, pass_thru, is_global) 

76 if len(jobs) == 0: 

77 print( 

78 "No job matches the search criteria. " 

79 "Hints: Double check id, and/or use --global to search all job queues." 

80 ) 

81 else: 

82 for job_id in sorted(jobs): 

83 results = service.cancel(job_id, pass_thru) 

84 if results[0]: 

85 print(f"Successfully canceled job with id '{job_id}'") 

86 else: 

87 print(f"Couldn't cancel job with id '{job_id}' ({results[1]})")