danicor commited on
Commit
6a7669d
·
verified ·
1 Parent(s): 9a2d1dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -56,48 +56,48 @@ class TranslationOrchestrator:
56
  self.start_job_processor()
57
 
58
  def load_worker_configs(self):
59
- """Load worker configurations with better debugging"""
60
  worker_index = 1
61
  workers_loaded = 0
62
 
63
  print("🔧 Loading worker configurations...")
64
-
65
  while True:
66
  url_key = f"WORKER_{worker_index}_URL"
67
  name_key = f"WORKER_{worker_index}_NAME"
68
-
69
  url = os.getenv(url_key)
70
  if not url:
71
- if worker_index == 1:
72
- print("❌ No workers configured! Please set WORKER_1_URL environment variable.")
73
  break
74
-
75
  name = os.getenv(name_key, f"Worker {worker_index}")
76
  priority = int(os.getenv(f"WORKER_{worker_index}_PRIORITY", "1"))
77
  max_concurrent = int(os.getenv(f"WORKER_{worker_index}_MAX_CONCURRENT", "3"))
78
-
79
  worker_id = f"worker_{worker_index}"
80
  config = WorkerConfig(
81
- url=url.rstrip('/'), # Remove trailing slash
82
  name=name,
83
  priority=priority,
84
  max_concurrent=max_concurrent
85
  )
86
-
87
  self.workers[worker_id] = WorkerStatus(config)
88
  workers_loaded += 1
89
- print(f"✅ Loaded worker: {name} at {url} (Priority: {priority}, Max: {max_concurrent})")
90
-
91
  worker_index += 1
92
-
93
- print(f"🎯 Total workers loaded: {workers_loaded}")
94
-
95
  if workers_loaded == 0:
96
- print("💡 To add workers, set environment variables like:")
97
- print(" WORKER_1_URL=https://your-worker-space.hf.space")
98
- print(" WORKER_1_NAME=Primary Worker")
99
- print(" WORKER_1_PRIORITY=1")
100
- print(" WORKER_1_MAX_CONCURRENT=3")
 
 
 
 
101
 
102
  def start_health_checker(self):
103
  def health_check_loop():
 
56
  self.start_job_processor()
57
 
58
  def load_worker_configs(self):
59
+ # حالت ۱: از env بخونه (روش اصلی)
60
  worker_index = 1
61
  workers_loaded = 0
62
 
63
  print("🔧 Loading worker configurations...")
64
+
65
  while True:
66
  url_key = f"WORKER_{worker_index}_URL"
67
  name_key = f"WORKER_{worker_index}_NAME"
68
+
69
  url = os.getenv(url_key)
70
  if not url:
 
 
71
  break
72
+
73
  name = os.getenv(name_key, f"Worker {worker_index}")
74
  priority = int(os.getenv(f"WORKER_{worker_index}_PRIORITY", "1"))
75
  max_concurrent = int(os.getenv(f"WORKER_{worker_index}_MAX_CONCURRENT", "3"))
76
+
77
  worker_id = f"worker_{worker_index}"
78
  config = WorkerConfig(
79
+ url=url.rstrip('/'),
80
  name=name,
81
  priority=priority,
82
  max_concurrent=max_concurrent
83
  )
84
+
85
  self.workers[worker_id] = WorkerStatus(config)
86
  workers_loaded += 1
87
+ print(f"✅ Loaded worker: {name} at {url}")
 
88
  worker_index += 1
89
+
90
+ # حالت ۲: اگه هیچ وورکری از env نیومد، دستی اضافه کن
 
91
  if workers_loaded == 0:
92
+ print("⚠️ No workers in env, using hardcoded fallback")
93
+ fallback_workers = [
94
+ WorkerConfig(url="https://danicor-w1.hf.space", name="Worker Local 1", priority=1, max_concurrent=1),
95
+ WorkerConfig(url="https://danicor-w2.hf.space", name="Worker Local 2", priority=1, max_concurrent=1),
96
+ ]
97
+ for i, cfg in enumerate(fallback_workers, start=1):
98
+ self.workers[f"worker_{i}"] = WorkerStatus(cfg)
99
+ print(f"✅ Hardcoded worker: {cfg.name} at {cfg.url}")
100
+
101
 
102
  def start_health_checker(self):
103
  def health_check_loop():