StarrySkyWorld commited on
Commit
90d59ab
·
1 Parent(s): c124de1

Fix: still startup status

Browse files
Files changed (4) hide show
  1. Dockerfile +1 -1
  2. main.py +20 -8
  3. server.py +3 -1
  4. startup.sh +5 -0
Dockerfile CHANGED
@@ -8,7 +8,7 @@ COPY . .
8
  COPY example.config.json config.json
9
 
10
  RUN apk update
11
- RUN apk add --no-cache chromium chromium-chromedriver
12
 
13
  RUN pip install --no-cache-dir -r requirements.txt
14
  RUN chmod +x /app/startup.sh
 
8
  COPY example.config.json config.json
9
 
10
  RUN apk update
11
+ RUN apk add --no-cache chromium chromium-chromedriver xvfb-run
12
 
13
  RUN pip install --no-cache-dir -r requirements.txt
14
  RUN chmod +x /app/startup.sh
main.py CHANGED
@@ -241,9 +241,24 @@ def build_chrome_options():
241
  options.binary_location = chrome_bin
242
  return options
243
 
244
- def register_one_account():
 
 
 
 
 
 
 
 
 
245
  options = build_chrome_options()
246
- driver = uc.Chrome(options=options, use_subprocess=True)
 
 
 
 
 
 
247
  email = None
248
  try:
249
  email, ok, cfg = register(driver)
@@ -262,8 +277,7 @@ def main():
262
  apply_config(cfg)
263
  print(f"\n{'='*50}\nGemini Business 批量注册 - 共 {TOTAL_ACCOUNTS} 个\n{'='*50}\n")
264
 
265
- options = build_chrome_options()
266
- driver = uc.Chrome(options=options, use_subprocess=True)
267
  success, fail, accounts = 0, 0, []
268
 
269
  for i in range(TOTAL_ACCOUNTS):
@@ -272,8 +286,7 @@ def main():
272
  try:
273
  driver.current_url # 检查driver是否有效
274
  except:
275
- options = build_chrome_options()
276
- driver = uc.Chrome(options=options, use_subprocess=True)
277
 
278
  email = None
279
  try:
@@ -287,8 +300,7 @@ def main():
287
  save_error_screenshot(driver, email)
288
  try: driver.quit()
289
  except: pass
290
- options = build_chrome_options()
291
- driver = uc.Chrome(options=options, use_subprocess=True)
292
 
293
  print(f"\n进度: {i+1}/{TOTAL_ACCOUNTS} | 成功: {success} | 失败: {fail}")
294
 
 
241
  options.binary_location = chrome_bin
242
  return options
243
 
244
+ def get_chromedriver_path():
245
+ candidate = os.getenv("CHROMEDRIVER_PATH")
246
+ if candidate and os.path.exists(candidate):
247
+ return candidate
248
+ for candidate in ("/usr/bin/chromedriver", "/usr/lib/chromium/chromedriver"):
249
+ if os.path.exists(candidate):
250
+ return candidate
251
+ return None
252
+
253
+ def create_driver():
254
  options = build_chrome_options()
255
+ driver_path = get_chromedriver_path()
256
+ if driver_path:
257
+ return uc.Chrome(options=options, use_subprocess=True, driver_executable_path=driver_path)
258
+ return uc.Chrome(options=options, use_subprocess=True)
259
+
260
+ def register_one_account():
261
+ driver = create_driver()
262
  email = None
263
  try:
264
  email, ok, cfg = register(driver)
 
277
  apply_config(cfg)
278
  print(f"\n{'='*50}\nGemini Business 批量注册 - 共 {TOTAL_ACCOUNTS} 个\n{'='*50}\n")
279
 
280
+ driver = create_driver()
 
281
  success, fail, accounts = 0, 0, []
282
 
283
  for i in range(TOTAL_ACCOUNTS):
 
286
  try:
287
  driver.current_url # 检查driver是否有效
288
  except:
289
+ driver = create_driver()
 
290
 
291
  email = None
292
  try:
 
300
  save_error_screenshot(driver, email)
301
  try: driver.quit()
302
  except: pass
303
+ driver = create_driver()
 
304
 
305
  print(f"\n进度: {i+1}/{TOTAL_ACCOUNTS} | 成功: {success} | 失败: {fail}")
306
 
server.py CHANGED
@@ -1,5 +1,6 @@
1
  from datetime import datetime
2
  from concurrent.futures import ThreadPoolExecutor
 
3
  import threading
4
  import uuid
5
 
@@ -44,6 +45,8 @@ def run_task(task_id):
44
  else:
45
  update_task(task_id, status="failed", error=f"register failed: {email}")
46
  except Exception as exc:
 
 
47
  update_task(task_id, status="failed", error=str(exc))
48
 
49
 
@@ -107,4 +110,3 @@ def task_info(task_id: str, x_api_key: str | None = Header(default=None)):
107
  if task["status"] == "failed":
108
  payload["error"] = task["error"]
109
  return payload
110
-
 
1
  from datetime import datetime
2
  from concurrent.futures import ThreadPoolExecutor
3
+ import traceback
4
  import threading
5
  import uuid
6
 
 
45
  else:
46
  update_task(task_id, status="failed", error=f"register failed: {email}")
47
  except Exception as exc:
48
+ print(f"[ERR] task {task_id} failed: {exc}")
49
+ print(traceback.format_exc())
50
  update_task(task_id, status="failed", error=str(exc))
51
 
52
 
 
110
  if task["status"] == "failed":
111
  payload["error"] = task["error"]
112
  return payload
 
startup.sh CHANGED
@@ -15,4 +15,9 @@ if [ -z "${CHROME_BIN:-}" ]; then
15
  fi
16
  fi
17
 
 
 
 
 
 
18
  exec uvicorn server:app --host 0.0.0.0 --port "${PORT:-7860}" --log-level debug --access-log
 
15
  fi
16
  fi
17
 
18
+ if command -v xvfb-run >/dev/null 2>&1; then
19
+ echo "Using xvfb-run for virtual display."
20
+ exec xvfb-run -a uvicorn server:app --host 0.0.0.0 --port "${PORT:-7860}" --log-level debug --access-log
21
+ fi
22
+
23
  exec uvicorn server:app --host 0.0.0.0 --port "${PORT:-7860}" --log-level debug --access-log