Skip to content

Commit e56a53f

Browse files
jirimoravcikTC-MO
andauthored
feat: add standby readiness probe docs (#1435)
This PR adds documentation for readiness probe in Actor standby along with code examples that show example handling of the readiness requests. --------- Co-authored-by: Michał Olender <[email protected]>
1 parent d5c19bc commit e56a53f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

sources/platform/actors/development/programming_interface/actor_standby.md

+66
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,72 @@ async def main() -> None:
7272
Please make sure to describe your Actors, their endpoints, and the schema for their
7373
inputs and outputs in your README.
7474

75+
### Readiness probe
76+
77+
Before Actor standby runs are ready to serve requests, the Apify platform checks the web server's readiness using a readiness probe.
78+
The platform sends a GET request to the path `/` with a header `x-apify-container-server-readiness-probe`. If the header is present in the request, you can perform an early return with a simple response to prevent wasting resources.
79+
80+
:::note Return a response
81+
82+
You must return a response; otherwise, the Actor run will never be marked as ready and won't process requests.
83+
84+
:::
85+
86+
87+
See example code below that distinguishes between "normal" and "readiness probe" requests.
88+
89+
<Tabs groupId="main">
90+
<TabItem value="JavaScript" label="JavaScript">
91+
92+
```js
93+
import http from 'http';
94+
import { Actor } from 'apify';
95+
96+
await Actor.init();
97+
98+
const server = http.createServer((req, res) => {
99+
res.writeHead(200, { 'Content-Type': 'text/plain' });
100+
if (req.headers['x-apify-container-server-readiness-probe']) {
101+
console.log('Readiness probe');
102+
res.end('Hello, readiness probe!\n');
103+
} else {
104+
console.log('Normal request');
105+
res.end('Hello from Actor Standby!\n');
106+
}
107+
});
108+
109+
server.listen(Actor.config.get('standbyPort'));
110+
```
111+
112+
</TabItem>
113+
<TabItem value="Python" label="Python">
114+
115+
```python
116+
from http.server import HTTPServer, SimpleHTTPRequestHandler
117+
from apify import Actor
118+
119+
120+
class GetHandler(SimpleHTTPRequestHandler):
121+
def do_GET(self) -> None:
122+
self.send_response(200)
123+
self.end_headers()
124+
if self.headers['x-apify-container-server-readiness-probe']:
125+
print('Readiness probe')
126+
self.wfile.write(b'Hello, readiness probe!')
127+
else:
128+
print('Normal request')
129+
self.wfile.write(b'Hello, normal request!')
130+
131+
132+
async def main() -> None:
133+
async with Actor:
134+
with HTTPServer(('', Actor.config.standby_port), GetHandler) as http_server:
135+
http_server.serve_forever()
136+
```
137+
138+
</TabItem>
139+
</Tabs>
140+
75141
## Determining an Actor is started in Standby
76142

77143
Actors that support Actor Standby can still be started in standard mode, for example from the Console or via the API.

0 commit comments

Comments
 (0)