44'''
55
66import asyncio
7- import typing
8-
7+ import warnings
98from runpod .serverless .modules .rp_logger import RunPodLogger
109from .rp_job import get_job
1110from .worker_state import Jobs
1413job_list = Jobs ()
1514
1615
17- def _default_concurrency_modifier (current_concurrency : int ) -> int :
18- """
19- Default concurrency modifier.
20-
21- This function returns the current concurrency without any modification.
22-
23- Args:
24- current_concurrency (int): The current concurrency.
25-
26- Returns:
27- int: The current concurrency.
28- """
29- return current_concurrency
30-
31-
3216class JobScaler ():
3317 """
3418 Job Scaler. This class is responsible for scaling the number of concurrent requests.
3519 """
3620
37- def __init__ (self , concurrency_modifier : typing . Any ):
38- if concurrency_modifier is None :
39- self . concurrency_modifier = _default_concurrency_modifier
40- else :
41- self . concurrency_modifier = concurrency_modifier
42-
43- self . background_get_job_tasks = set ()
44- self . job_history = []
45- self . current_concurrency = 1
21+ def __init__ (self , concurrency_modifier = None ):
22+ if concurrency_modifier :
23+ warnings . warn (
24+ "JobScaler(concurrency_modifier) is deprecated " ,
25+ "and will be removed in a future version. "
26+ "Please remove `concurrency_modifier` parameter." ,
27+ DeprecationWarning ,
28+ stacklevel = 2
29+ )
4630 self ._is_alive = True
4731
4832 def is_alive (self ):
@@ -65,22 +49,12 @@ async def get_jobs(self, session):
6549 List[Any]: A list of job data retrieved from the server.
6650 """
6751 while self .is_alive ():
68- self .current_concurrency = self .concurrency_modifier (self .current_concurrency )
69- log .debug (f"Concurrency set to: { self .current_concurrency } " )
70-
7152 log .debug (f"Jobs in progress: { job_list .get_job_count ()} " )
72- if job_list .get_job_count () < self .current_concurrency and self .is_alive ():
73- log .debug ("Job list is less than concurrency, getting more jobs." )
74-
75- tasks = [
76- asyncio .create_task (get_job (session , retry = False ))
77- for _ in range (self .current_concurrency if job_list .get_job_list () else 1 )
78- ]
7953
80- for job_future in asyncio .as_completed (tasks ):
81- job = await job_future
82- self .job_history .append (1 if job else 0 )
83- if job :
84- yield job
54+ tasks = [
55+ asyncio .create_task (get_job (session , retry = False ))
56+ ]
8557
86- await asyncio .sleep (0 )
58+ for job_future in asyncio .as_completed (tasks ):
59+ if job := await job_future :
60+ yield job
0 commit comments