YTShortMakerArchx commited on
Commit
f7f7a6b
·
verified ·
1 Parent(s): b4cef8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -9
app.py CHANGED
@@ -300,34 +300,47 @@ async def _pick(stype: str) -> Optional[str]:
300
 
301
  for url in urls:
302
  c = status_cache.get(url, {})
303
- if not c.get("online") or not c.get("worker_ready", True):
304
  continue
305
  if stype == "ffmpeg":
306
- load = c.get("running", 1) + c.get("waiting", 1)
 
 
 
 
307
  else:
308
- load = 0 if c.get("can_submit") else 1
309
  if load < best_load:
310
  best_load = load
311
  best_url = url
312
 
313
  if best_url:
 
 
 
 
 
314
  return best_url
315
 
316
- results = await asyncio.gather(*[_check_one(url, stype) for url in urls])
 
317
  best_url = None
318
  best_load = float('inf')
319
 
320
  for r in results:
321
- if not isinstance(r, dict) or not r.get("online") or not r.get("worker_ready", True):
322
  continue
323
- if stype == "ffmpeg":
324
- load = r.get("running", 1) + r.get("waiting", 1)
325
- else:
326
- load = 0 if r.get("can_submit") else 1
327
  if load < best_load:
328
  best_load = load
329
  best_url = r["url"]
330
 
 
 
 
 
 
 
331
  return best_url
332
 
333
 
 
300
 
301
  for url in urls:
302
  c = status_cache.get(url, {})
303
+ if not c.get("online", True) and c: # skip only if we know it's offline
304
  continue
305
  if stype == "ffmpeg":
306
+ # use can_submit so optimistic reservation is visible here too
307
+ if not c.get("can_submit", True):
308
+ load = 1
309
+ else:
310
+ load = 0
311
  else:
312
+ load = 0 if c.get("can_submit", True) else 1
313
  if load < best_load:
314
  best_load = load
315
  best_url = url
316
 
317
  if best_url:
318
+ # optimistic reservation — works for all types now
319
+ if best_url in status_cache:
320
+ status_cache[best_url]["can_submit"] = False
321
+ status_cache[best_url]["slot_available"] = False
322
+ status_cache[best_url]["queue_full"] = True
323
  return best_url
324
 
325
+ # live fallback
326
+ results = await asyncio.gather(*[_check_one(url, stype) for url in urls])
327
  best_url = None
328
  best_load = float('inf')
329
 
330
  for r in results:
331
+ if not isinstance(r, dict) or not r.get("online"):
332
  continue
333
+ load = 0 if r.get("can_submit", False) else 1
 
 
 
334
  if load < best_load:
335
  best_load = load
336
  best_url = r["url"]
337
 
338
+ if best_url:
339
+ if best_url in status_cache:
340
+ status_cache[best_url]["can_submit"] = False
341
+ status_cache[best_url]["slot_available"] = False
342
+ status_cache[best_url]["queue_full"] = True
343
+
344
  return best_url
345
 
346