-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathtest_worker.py
More file actions
executable file
·52 lines (43 loc) · 1.38 KB
/
test_worker.py
File metadata and controls
executable file
·52 lines (43 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
"""
Test Worker - for demonstrating Waverless complete workflow
"""
import os
import time
from runpod.serverless import start
# Configure Waverless address
os.environ["RUNPOD_WEBHOOK_GET_JOB"] = "http://localhost:8080/runpod/job-take/$ID"
os.environ["RUNPOD_WEBHOOK_PING"] = "http://localhost:8080/runpod/ping/$ID"
os.environ["RUNPOD_POD_ID"] = "test-worker-001"
os.environ["RUNPOD_PING_INTERVAL"] = "10000"
def handler(job):
"""
Simple task handler
"""
print(f"\n{'='*50}")
print(f"Processing job: {job['id']}")
print(f"Input: {job.get('input', {})}")
print(f"{'='*50}\n")
job_input = job.get("input", {})
prompt = job_input.get("prompt", "")
# Simulate processing time
print("Processing...")
time.sleep(3)
result = {
"result": f"Processed: {prompt}",
"worker_id": os.environ["RUNPOD_POD_ID"],
"timestamp": time.time()
}
print(f"\n{'='*50}")
print(f"Job {job['id']} completed")
print(f"Result: {result}")
print(f"{'='*50}\n")
return result
if __name__ == "__main__":
print("\n" + "="*70)
print("Starting Waverless Test Worker")
print("="*70)
print(f"Worker ID: {os.environ['RUNPOD_POD_ID']}")
print(f"Waverless URL: {os.environ['RUNPOD_WEBHOOK_GET_JOB'].replace('$ID', os.environ['RUNPOD_POD_ID'])}")
print("="*70 + "\n")
start({"handler": handler})