@@ -94,9 +94,11 @@ def __hash__(self) -> int:
9494
9595
9696T = TypeVar ("T" )
97+ A = TypeVar ("A" )
98+ D = TypeVar ("D" )
9799
98100
99- class Scheduler (abc .ABC , Generic [T ]):
101+ class Scheduler (abc .ABC , Generic [T , A , D ]):
100102 """
101103 An interface abstracting functionalities of a scheduler.
102104 Implementers need only implement those methods annotated with
@@ -126,7 +128,7 @@ def close(self) -> None:
126128
127129 def submit (
128130 self ,
129- app : AppDef ,
131+ app : A ,
130132 cfg : T ,
131133 workspace : Optional [str ] = None ,
132134 ) -> str :
@@ -150,7 +152,7 @@ def submit(
150152 return self .schedule (dryrun_info )
151153
152154 @abc .abstractmethod
153- def schedule (self , dryrun_info : AppDryRunInfo ) -> str :
155+ def schedule (self , dryrun_info : D ) -> str :
154156 """
155157 Same as ``submit`` except that it takes an ``AppDryRunInfo``.
156158 Implementers are encouraged to implement this method rather than
@@ -166,7 +168,7 @@ def schedule(self, dryrun_info: AppDryRunInfo) -> str:
166168
167169 raise NotImplementedError ()
168170
169- def submit_dryrun (self , app : AppDef , cfg : T ) -> AppDryRunInfo :
171+ def submit_dryrun (self , app : A , cfg : T ) -> D :
170172 """
171173 Rather than submitting the request to run the app, returns the
172174 request object that would have been submitted to the underlying
@@ -179,14 +181,16 @@ def submit_dryrun(self, app: AppDef, cfg: T) -> AppDryRunInfo:
179181 resolved_cfg = self .run_opts ().resolve (cfg )
180182 # pyre-fixme: _submit_dryrun takes Generic type for resolved_cfg
181183 dryrun_info = self ._submit_dryrun (app , resolved_cfg )
182- for role in app .roles :
183- dryrun_info = role .pre_proc (self .backend , dryrun_info )
184- dryrun_info ._app = app
185- dryrun_info ._cfg = resolved_cfg
184+
185+ if isinstance (app , AppDef ):
186+ for role in app .roles :
187+ dryrun_info = role .pre_proc (self .backend , dryrun_info )
188+ dryrun_info ._app = app
189+ dryrun_info ._cfg = resolved_cfg
186190 return dryrun_info
187191
188192 @abc .abstractmethod
189- def _submit_dryrun (self , app : AppDef , cfg : T ) -> AppDryRunInfo :
193+ def _submit_dryrun (self , app : A , cfg : T ) -> D :
190194 raise NotImplementedError ()
191195
192196 def run_opts (self ) -> runopts :
@@ -345,18 +349,19 @@ def _pre_build_validate(self, app: AppDef, scheduler: str, cfg: T) -> None:
345349 """
346350 pass
347351
348- def _validate (self , app : AppDef , scheduler : str , cfg : T ) -> None :
352+ def _validate (self , app : A , scheduler : str , cfg : T ) -> None :
349353 """
350354 Validates after workspace build whether application is consistent with the scheduler.
351355
352356 Raises error if application is not compatible with scheduler
353357 """
354- for role in app .roles :
355- if role .resource == NULL_RESOURCE :
356- raise ValueError (
357- f"No resource for role: { role .image } ."
358- f" Did you forget to attach resource to the role"
359- )
358+ if isinstance (app , AppDef ):
359+ for role in app .roles :
360+ if role .resource == NULL_RESOURCE :
361+ raise ValueError (
362+ f"No resource for role: { role .image } ."
363+ f" Did you forget to attach resource to the role"
364+ )
360365
361366
362367def filter_regex (regex : str , data : Iterable [str ]) -> Iterable [str ]:
0 commit comments