Skip to content

Commit d3ec258

Browse files
authored
Updates container lifecycle docs (#30212)
1 parent eafa62a commit d3ec258

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/content/docs/containers/examples/status-hooks.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ products:
1212
---
1313

1414
When a Container starts, stops, becomes idle, and errors, it can trigger code execution in a Worker
15-
that has defined status hooks on the `Container` class. Refer to the [Container package docs](https://github.com/cloudflare/containers/blob/main/README.md#lifecycle-hooks) for more details.
15+
that has defined status hooks on the `Container` class. Refer to the [Container class lifecycle hooks](/containers/container-class/#lifecycle-hooks) for more details.
1616

1717
```ts
1818
import { Container } from "@cloudflare/containers";

src/content/docs/containers/platform-details/architecture.mdx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,30 @@ should be built for the `linux/amd64` architecture, and should stay within
9292

9393
### Container shutdown
9494

95-
If you do not set [`sleepAfter`](https://github.com/cloudflare/containers/blob/main/README.md#properties)
95+
If you do not set [`sleepAfter`](/containers/container-class/#sleepafter)
9696
on your Container class, or stop the instance manually, the container will shut down soon after the container stops receiving requests.
9797
By setting `sleepAfter`, the container will stay alive for approximately the specified duration.
9898

99-
You can manually shut down a container instance by calling `stop()` or `destroy()` on it. Refer to the [Container package docs](https://github.com/cloudflare/containers/blob/main/README.md#container-methods) for more details.
99+
You can manually shut down a container instance by calling [`stop()`](/containers/container-class/#stop) or [`destroy()`](/containers/container-class/#destroy) on it.
100100

101101
When a container instance is going to be shut down, it is sent a `SIGTERM` signal,
102102
and then a `SIGKILL` signal after 15 minutes. You should perform any necessary
103103
cleanup to ensure a graceful shutdown in this time.
104104

105+
### Lifecycle hooks
106+
107+
The [`Container` class](/containers/container-class/) provides hooks that run Worker code when the container changes state:
108+
109+
- [`onStart()`](/containers/container-class/#onstart) — Runs after the container has started.
110+
111+
- [`onStop()`](/containers/container-class/#onstop) — Runs after the container process exits. Receives the exit code and reason for the stop.
112+
113+
- [`onActivityExpired()`](/containers/container-class/#onactivityexpired) — Runs when the [`sleepAfter`](/containers/container-class/#sleepafter) timer expires with no incoming requests. The default implementation calls `stop()` to shut down the container. You can use this to only stop the container on certain conditions.
114+
115+
- [`onError()`](/containers/container-class/#onerror) — Runs when the container exits with an error.
116+
117+
Refer to the [status hooks example](/containers/examples/status-hooks/) for a full implementation.
118+
105119
#### Persistent disk
106120

107121
All disk is ephemeral. When a Container instance goes to sleep, the next time

0 commit comments

Comments
 (0)