Skip to content

feat: add standby readiness probe docs #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,72 @@ async def main() -> None:
Please make sure to describe your Actors, their endpoints, and the schema for their
inputs and outputs in your README.

### Readiness probe

Before Actor standby runs are ready to serve requests, the Apify platform checks the web server's readiness using a readiness probe.
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.

:::note Return a response

You must return a response; otherwise, the Actor run will never be marked as ready and won't process requests.

:::


See example code below that distinguishes between "normal" and "readiness probe" requests.

<Tabs groupId="main">
<TabItem value="JavaScript" label="JavaScript">

```js
import http from 'http';
import { Actor } from 'apify';

await Actor.init();

const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
if (req.headers['x-apify-container-server-readiness-probe']) {
console.log('Readiness probe');
res.end('Hello, readiness probe!\n');
} else {
console.log('Normal request');
res.end('Hello from Actor Standby!\n');
}
});

server.listen(Actor.config.get('standbyPort'));
```

</TabItem>
<TabItem value="Python" label="Python">

```python
from http.server import HTTPServer, SimpleHTTPRequestHandler
from apify import Actor


class GetHandler(SimpleHTTPRequestHandler):
def do_GET(self) -> None:
self.send_response(200)
self.end_headers()
if self.headers['x-apify-container-server-readiness-probe']:
print('Readiness probe')
self.wfile.write(b'Hello, readiness probe!')
else:
print('Normal request')
self.wfile.write(b'Hello, normal request!')


async def main() -> None:
async with Actor:
with HTTPServer(('', Actor.config.standby_port), GetHandler) as http_server:
http_server.serve_forever()
```

</TabItem>
</Tabs>

## Determining an Actor is started in Standby

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