Skip to content

Commit 2ce9597

Browse files
author
Al Chu11
committed
tutorials: Add a flux job cancel tutorial
1 parent 7412532 commit 2ce9597

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
.. _flux-job-cancel:
2+
.. _flux-job-cancelall:
3+
4+
========================
5+
How to Cancel a Flux Job
6+
========================
7+
8+
Inevitably submitted jobs will have to be canceled for one reason or another. This tutorial
9+
will show you how.
10+
11+
----------------------------
12+
How to Cancel a Job by Jobid
13+
----------------------------
14+
15+
The basic way to cancel a job is through ``flux job cancel``. All you have to do is specify
16+
the jobid on the command line. Here is a simple example after submitting a job.
17+
18+
.. code-block:: console
19+
20+
$ flux mini submit sleep 100
21+
ƒh35Dh5qRyq
22+
23+
$ flux jobs ƒh35Dh5qRyq
24+
JOBID USER NAME ST NTASKS NNODES TIME INFO
25+
ƒh35Dh5qRyq achu sleep R 1 1 13.33s corona174
26+
27+
$ flux job cancel ƒh35Dh5qRyq
28+
29+
<snip wait a little bit>
30+
31+
$ flux jobs ƒh35Dh5qRyq
32+
JOBID USER NAME ST NTASKS NNODES TIME INFO
33+
ƒh35Dh5qRyq achu sleep CA 1 1 20.18s corona174
34+
35+
In the above example we submitted a simple job via ``flux mini submit`` that simply
36+
runs ``sleep``. Passing the resulting jobid to ``flux jobs`` shows that it is
37+
running (state is ``R``).
38+
39+
We cancel the job simply by passing the jobid to ``flux job cancel``. After waiting
40+
a little bit, we see that the job is now canceled in ``flux jobs`` (state is ``CA``).
41+
42+
While we only passed one jobid to ``flux job cancel`` in this example, multiple jobids can be
43+
passed on the commandline to cancel many jobs.
44+
45+
Note that in this particular example we happened to know the jobid of our job. If you do
46+
not know the the jobid of your job, you can always use ``flux jobs`` to see a list of all
47+
your currently active jobs.
48+
49+
------------------------
50+
Cancelling All Your Jobs
51+
------------------------
52+
53+
The ``flux job cancelall`` command allows you to cancel jobs without specifying jobids.
54+
By default it cancels all of your active jobs, but several options allow you to target a subset of the jobs.
55+
56+
To start off, lets create 100 jobs that will sleep infinitely. We will use the special ``--cc`` (carbon copy)
57+
option to ``flux mini submit`` that will submit 100 duplicate copies of the ``sleep`` job.
58+
59+
.. code-block:: console
60+
61+
$ flux mini submit --cc=1-100 sleep inf
62+
<snip - many job ids printed out>
63+
64+
$ flux jobs
65+
JOBID USER NAME ST NTASKS NNODES TIME INFO
66+
ƒjTWS5m3 achu sleep S 1 - -
67+
ƒjTWS5m4 achu sleep S 1 - -
68+
ƒjTWS5m5 achu sleep S 1 - -
69+
ƒjTWS5m6 achu sleep S 1 - -
70+
<snip - there are many jobs waiting to be run>
71+
ƒjTWS5m2 achu sleep R 1 1 8.858s corona212
72+
ƒjTWS5m1 achu sleep R 1 1 8.860s corona212
73+
ƒjTUx6Um achu sleep R 1 1 8.870s corona212
74+
ƒjTUx6Uk achu sleep R 1 1 8.870s corona212
75+
ƒjTUx6Uj achu sleep R 1 1 8.870s corona212
76+
ƒjTUx6Ui achu sleep R 1 1 8.871s corona212
77+
<snip - there are many jobs running>
78+
79+
As you can see, we have a lot of jobs waiting to run (state ``S``) and a lot of running jobs (state ``R``).
80+
81+
Lets first ``flux job cancelall`` without any options.
82+
83+
.. code-block:: console
84+
85+
$ flux job cancelall
86+
flux-job: Command matched 100 jobs (-f to confirm)
87+
88+
As you can see, ``flux job cancelall`` found all 100 jobs to cancel, but it hasn't canceled them yet. In order to go through
89+
with the cancellation you must specify the ``-f`` (or ``--force``) option.
90+
91+
.. code-block:: console
92+
93+
$ flux job cancelall -f
94+
flux-job: Canceled 100 jobs (0 errors)
95+
96+
$ flux jobs
97+
JOBID USER NAME ST NTASKS NNODES TIME INFO
98+
99+
As you can see, all the jobs are now canceled after passing the ``-f`` option to ``flux job cancelall``. ``flux jobs``
100+
confirms there are no longer any of our jobs running or waiting to run.
101+
102+
``flux job cancellall`` has several options to filter the jobs to cancel. Perhaps the most commonly used
103+
option is the ``-S`` or ``--states`` option. The ``--states`` option specifies the state(s) of a job to cancel. The most
104+
common states to target are ``pending`` and ``running``. Lets resubmit our 100 jobs and see the result
105+
of trying to cancel ``pending`` vs ``running`` jobs.
106+
107+
.. code-block:: console
108+
109+
$ flux mini submit --cc=1-100 sleep inf
110+
<snip - many job ids printed out>
111+
112+
$ flux job cancelall --states=pending
113+
flux-job: Command matched 52 jobs (-f to confirm)
114+
115+
$ flux job cancelall --states=running
116+
flux-job: Command matched 48 jobs (-f to confirm)
117+
118+
As you can see ``flux job cancelall --states=pending`` would target the 52 pending jobs for cancellation and
119+
``flux job cancelall --states=running`` would target the current 48 running jobs for cancellation.
120+
121+
And that's it! If you have any questions, please
122+
`let us know <https://github.com/flux-framework/flux-docs/issues>`_.

tutorials/commands/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Welcome to the Command Tutorials! These tutorials should help you to map specifi
77
with your use case, and then see detailed usage.
88

99
- ``flux mini submit/flux mini run`` (:ref:`flux-mini-submit`): "Submit a job in a Flux instance"
10+
- ``flux job cancel/flux job cancelall`` (:ref:`flux-job-cancel`): "Cancel a job you submitted"
1011
- ``flux proxy`` (:ref:`ssh-across-clusters`): "Send commands to a Flux instance across clusters using ssh"
1112

1213
This section is currently 🚧️ under construction 🚧️, so please come back later to see more command tutorials!
@@ -17,4 +18,5 @@ This section is currently 🚧️ under construction 🚧️, so please come bac
1718
:caption: Command Tutorials
1819

1920
flux-mini-submit
21+
flux-job-cancel
2022
ssh-across-clusters

0 commit comments

Comments
 (0)