Skip to content

Commit eede1ec

Browse files
committed
Add cancel_process.md
1 parent e7a08bc commit eede1ec

1 file changed

Lines changed: 62 additions & 0 deletions

File tree

docs/cancel_process.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
### Cancelling a Running WPS Process
2+
3+
The `handle_cancel` function provides an HTTP endpoint for **gracefully cancelling a running WPS process** by sending it a `SIGINT` and updating its status in the PyWPS database.
4+
5+
#### Endpoint
6+
7+
```
8+
POST /wps/cancel-process
9+
```
10+
11+
This endpoint is handled by the `handle_cancel` function via WSGI middleware. It is only accessible using the POST method.
12+
13+
#### Request Format
14+
15+
**Headers**:
16+
`Content-Type: application/json`
17+
18+
**Body**:
19+
20+
```json
21+
{ "uuid": "your-process-uuid" }
22+
```
23+
24+
- `uuid` is required and must refer to a running WPS process with a recorded PID in the PyWPS database.
25+
26+
#### Successful Response
27+
28+
```json
29+
{ "message": "Process your-process-uuid (PID 12345) cancelled." }
30+
```
31+
32+
HTTP Status: `200 OK`
33+
34+
#### Error Responses
35+
36+
| Status Code | Reason |
37+
| --------------------------- | ------------------------------------------------------ |
38+
| `400 Bad Request` | Missing or invalid JSON, or UUID not provided |
39+
| `403 Forbidden` | Permission denied when trying to send signal |
40+
| `404 Not Found` | No process found for the given UUID or no PID recorded |
41+
| `405 Method Not Allowed` | Request method was not POST |
42+
| `500 Internal Server Error` | Internal database or signal error |
43+
44+
---
45+
46+
#### Internals
47+
48+
- Uses `pywps.dblog.get_session()` to query the process from the database.
49+
- Sends `SIGINT` (graceful stop) to the stored PID using `os.kill()`.
50+
- Updates process status using `store_status()` to reflect cancellation as `WPS_STATUS.FAILED`.
51+
- Cleans up the temporary directories using [response.clean()](https://github.com/geopython/pywps/blob/10dd07a9ee55c3033e240fa882eebadfc3ac4ad8/pywps/app/Process.py#L333).
52+
- Closes the database session.
53+
54+
---
55+
56+
#### Example `curl` Request
57+
58+
```bash
59+
curl -X POST http://localhost:5000/wps/cancel-process \
60+
-H "Content-Type: application/json" \
61+
-d '{"uuid": "abcd-1234-efgh-5678"}'
62+
```

0 commit comments

Comments
 (0)