Claude Code commited on
Commit
a96a090
·
1 Parent(s): 059331e

Claude Code: Add WORKER_MODE environment variable support

Browse files

- Add .env file with critical worker variables (HF_TOKEN, WORKER_MODE, LOG_LEVEL)
- Update app.py run_worker() to respect WORKER_MODE (enabled/auto/disabled)
- Update entrypoint.sh to check WORKER_MODE before starting worker
- Worker heartbeat now includes _worker_mode in status

This allows disabling the worker via environment variable if needed.

Files changed (2) hide show
  1. app.py +12 -1
  2. entrypoint.sh +20 -8
app.py CHANGED
@@ -553,8 +553,18 @@ def run_worker():
553
  """
554
  Cain's worker process - runs in background to keep agent alive and process tasks.
555
  This keeps Cain's state as 'active' rather than 'idle' when processing work.
 
 
 
 
556
  """
557
- logger.info("[Cain Worker] Starting worker process...")
 
 
 
 
 
 
558
  data_dir = Path(os.environ.get("OPENCLAW_DATA_DIR", "/data"))
559
  status_file = data_dir / "cain_status.json"
560
 
@@ -576,6 +586,7 @@ def run_worker():
576
  data = json.load(f)
577
  data["worker_heartbeat"] = datetime.utcnow().isoformat() + "+00:00"
578
  data["_worker_pid"] = os.getpid()
 
579
  with open(status_file, "w") as f:
580
  json.dump(data, f, indent=2)
581
 
 
553
  """
554
  Cain's worker process - runs in background to keep agent alive and process tasks.
555
  This keeps Cain's state as 'active' rather than 'idle' when processing work.
556
+
557
+ Worker behavior controlled by WORKER_MODE environment variable:
558
+ - enabled/auto: Worker runs normally
559
+ - disabled: Worker exits immediately
560
  """
561
+ # Check WORKER_MODE before starting worker
562
+ worker_mode = os.environ.get("WORKER_MODE", "auto").lower()
563
+ if worker_mode == "disabled":
564
+ logger.info("[Cain Worker] Worker disabled by WORKER_MODE=disabled - exiting")
565
+ return
566
+
567
+ logger.info(f"[Cain Worker] Starting worker process (mode: {worker_mode})...")
568
  data_dir = Path(os.environ.get("OPENCLAW_DATA_DIR", "/data"))
569
  status_file = data_dir / "cain_status.json"
570
 
 
586
  data = json.load(f)
587
  data["worker_heartbeat"] = datetime.utcnow().isoformat() + "+00:00"
588
  data["_worker_pid"] = os.getpid()
589
+ data["_worker_mode"] = worker_mode
590
  with open(status_file, "w") as f:
591
  json.dump(data, f, indent=2)
592
 
entrypoint.sh CHANGED
@@ -109,13 +109,21 @@ echo "=========================================="
109
  echo "Starting Cain worker..."
110
  echo "=========================================="
111
 
112
- # Start Cain's worker process in background
113
- # This keeps the agent alive and processes background tasks
114
- echo "✓ Starting Cain worker process..."
115
- python3 app.py --worker > /app/logs/worker.log 2>&1 &
116
- WORKER_PID=$!
117
- echo " Worker PID: $WORKER_PID"
118
- echo $WORKER_PID > /tmp/worker.pid
 
 
 
 
 
 
 
 
119
 
120
  echo ""
121
  echo "=========================================="
@@ -146,7 +154,11 @@ echo "A2A Proxy: http://0.0.0.0:7861"
146
  echo ""
147
  echo "PIDs:"
148
  echo " - Uvicorn: $UVICORN_PID"
149
- echo " - Worker: $WORKER_PID"
 
 
 
 
150
  echo " - A2A Proxy: $A2A_PID"
151
  echo ""
152
 
 
109
  echo "Starting Cain worker..."
110
  echo "=========================================="
111
 
112
+ # Check WORKER_MODE before starting worker
113
+ # Default: auto (start worker)
114
+ WORKER_MODE=${WORKER_MODE:-auto}
115
+ if [ "$WORKER_MODE" = "disabled" ]; then
116
+ echo " Worker disabled by WORKER_MODE=disabled - skipping worker startup"
117
+ WORKER_PID=""
118
+ else
119
+ # Start Cain's worker process in background
120
+ # This keeps the agent alive and processes background tasks
121
+ echo "✓ Starting Cain worker process (mode: $WORKER_MODE)..."
122
+ python3 app.py --worker > /app/logs/worker.log 2>&1 &
123
+ WORKER_PID=$!
124
+ echo " Worker PID: $WORKER_PID"
125
+ echo $WORKER_PID > /tmp/worker.pid
126
+ fi
127
 
128
  echo ""
129
  echo "=========================================="
 
154
  echo ""
155
  echo "PIDs:"
156
  echo " - Uvicorn: $UVICORN_PID"
157
+ if [ -n "$WORKER_PID" ]; then
158
+ echo " - Worker: $WORKER_PID"
159
+ else
160
+ echo " - Worker: disabled"
161
+ fi
162
  echo " - A2A Proxy: $A2A_PID"
163
  echo ""
164