|
1 | | -# RunPod Pod Worker |
| 1 | +# The Serverless Worker |
2 | 2 |
|
3 | | -To convert a Pod to a Worker, you need to add the following annotations to the Pod: |
4 | 3 |
|
5 | | -## Environment Variables |
6 | 4 |
|
7 | | -```bash |
8 | | -# Development |
9 | | -RUNPOD_DEBUG= # Set to 'true' to enable debug mode, otherwise leave blank |
10 | | -RUNPOD_DEBUG_LEVEL= # ERROR, WARN, INFO, DEBUG |
| 5 | +## Worker Refresh |
11 | 6 |
|
12 | | -# Realtime |
13 | | -RUNPOD_REALTIME_PORT= # Port to listen on for realtime connections (Default: None) |
14 | | -RUNPOD_REALTIME_CONCURRENCY= # Number of workers to spawn (Default: 1) |
15 | | -``` |
| 7 | +For more complex operations where you are downloading files or making changes to the worker it can be beneficial to refresh the worker between jobs. This can be accomplished by enabling a refresh_worker worker flag in 1 of two ways: |
16 | 8 |
|
17 | | -The following environment variables are set automatically by RunPod, you DO NOT need to set them manually: |
18 | | - |
19 | | -```bash |
20 | | -# API Endpoints |
21 | | -RUNPOD_AI_API_KEY= # Serverless API Key |
22 | | -RUNPOD_WEBHOOK_GET_JOB= # URL to get job work from |
23 | | -RUNPOD_WEBHOOK_POST_OUTPUT= # URL to post output to |
24 | | -RUNPOD_WEBHOOK_PING= # URL to ping |
25 | | -RUNPOD_PING_INTERVAL= # Interval in milliseconds to ping the API (Default: 10000) |
26 | | - |
27 | | -RUNPOD_ENDPOINT_ID= # Endpoint ID |
28 | | -RUNPOD_ENDPOINT_SECRET= # Endpoint Secret (SET BY RUNPOD Replaces RUNPOD_AI_API_KEY, not implemented yet) |
29 | | -``` |
30 | | - |
31 | | -### Additional Variables |
32 | | - |
33 | | -These are variables that are accessed from the RunPod container and not required to be set manually: |
34 | | - |
35 | | -```bash |
36 | | -# Pod Information |
37 | | -RUNPOD_POD_ID= # Pod ID |
38 | | -``` |
39 | | - |
40 | | -## Error Handling |
41 | | - |
42 | | -If an error occurs, the worker will send a message to the API with the error message and the job will be marked as failed. |
43 | | - |
44 | | -To report a job error call `job.error(worker_id, job_id, error_message)`. |
45 | | - |
46 | | ---- |
47 | | - |
48 | | -## Worker Lifecycle Management |
49 | | - |
50 | | -The duration of the worker is managed within the [lifecycle](../PodWorker/modules/lifecycle.py) module. |
51 | | - |
52 | | -The worker starts with a TTL as specified by the environment variable `TERMINATE_IDLE_TIME` or defaults to 60 seconds as specified with `self.ttl`. When a new job is received, a `work_in_progress` flag is set. When the job is completed, the `work_in_progress` flag is cleared and the TTL is reset. If the `work_in_progress` flag is not cleared within the `work_timeout` period, the worker will exit. |
53 | | - |
54 | | - If the worker does not receive a new job within idle period, the worker will exit. |
55 | | - |
56 | | -## Local Testing |
57 | | - |
58 | | -To test locally, create the file `test_input.json` in the root directory that contains the following: |
59 | | - |
60 | | -```json |
61 | | -{ |
62 | | - "id": "LOCAL-TEST", |
63 | | - "input":{} |
64 | | -} |
65 | | -``` |
66 | | - |
67 | | -If the required webhook environment variables are not set, the worker will default to local testing. |
| 9 | + 1. Enable on start with `runpod.serverless.start({"handler": handler, "refresh_worker": True})`, this will refresh the worker after every job return, even if the handler raises an error. |
| 10 | + 2. Return `refresh_worker=True` as a top level dictionary key in the handler return. This can selectively be used to refresh the worker based on the job return. |
0 commit comments