Skip to content

Commit 681e45c

Browse files
weltekialexellis
authored andcommitted
Add documentation for cancelling async invocations
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
1 parent 20b02a3 commit 681e45c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/reference/async.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ X-Start-Time: 1543915495384346700
7171

7272
Alternatively you can specify another asynchronous or synchronous function to run instead.
7373

74+
### Cancel async invocations
75+
76+
Sometimes you might need to cancel an ongoing or queued invocation. Asynchronous invocations can be cancelled by making an HTTP `DELETE` request to `/async-function/<name>/<call-id>`. The call id is the X-Call-Id header that was returned when submitting the async invocation.
77+
78+
```bash
79+
$ curl -i \
80+
-X DELETE \
81+
http://127.0.0.1:8080/async-function/sleep/ee7fcaeb-82b7-4834-b677-45005c5f0b1b
82+
```
83+
84+
A `202 Accepted` message will be issued if the request is successful.
85+
86+
Reasons why you might need to cancel an async request:
87+
88+
- Cancel long running tasks.
89+
- Cancel failing invocations, e.g due to an invalid payload, that would otherwise be retried by the queue-worker until the max retry limit is reached.
90+
- Cancel all invocations that are part of a batch if one fails.
91+
92+
7493
### Making an asynchronous call from another function
7594

7695
You cannot use the address `127.0.0.1` when calling the gateway from within a function, because this refers to the function's container and local network, not the gateway's.

docs/reference/rest-api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ You can expose Functions with a REST-like mapping or on custom subdomains with t
132132

133133
* See also: [Custom domains and REST-like mappings for functions](/reference/tls-functions)
134134

135+
### Cancel an async invocation
136+
137+
To cancel an asynchronous function invocation an HTTP `DELETE` request can be made to the async function endpoint with the call id of the invocation that needs to be cancelled as a path parameter: `/async-function/<name>.<namespace>/<call-id>`
138+
139+
```bash
140+
curl -i \
141+
-X DELETE \
142+
http://127.0.0.1:8080/async-function/sleep/ee7fcaeb-82b7-4834-b677-45005c5f0b1b
143+
```
144+
145+
A `202 Accepted` message will be issued if the request is successful.
146+
147+
The invocation will be cancelled if it is in progress or removed from the queue otherwise.
148+
135149
### Deploy a function
136150

137151
The minimum valid payload includes the function's name and image, however there are many other fields available.

0 commit comments

Comments
 (0)