Skip to content

Commit beac0ca

Browse files
committed
Allow passing a vanilla JobExecutorConfig to batch scheduler executors
without getting odd errors later.
1 parent e6b6de3 commit beac0ca

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/psij/executors/batch/batch_scheduler_executor.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ def __init__(self, launcher_log_file: Optional[Path] = None,
113113
if 'PSIJ_BATCH_KEEP_FILES' in os.environ:
114114
self.keep_files = True
115115

116+
@classmethod
117+
def _from_config(cls, config: JobExecutorConfig) -> 'BatchSchedulerExecutorConfig':
118+
new = cls()
119+
new.work_directory = config.work_directory
120+
new.launcher_log_file = config.launcher_log_file
121+
return new
122+
116123

117124
class InvalidJobStateError(Exception):
118125
"""An exception that signals that a job cannot be cancelled due to it being already done."""
@@ -199,14 +206,21 @@ def __init__(self, url: Optional[str] = None,
199206
An configuration for this executor instance; if none is specified, a default
200207
configuration is used.
201208
"""
202-
super().__init__(url=url, config=config if config else BatchSchedulerExecutorConfig())
209+
super().__init__(url=url, config=self._get_config(config))
203210
assert config
204211
self.work_directory = config.work_directory / self.name
205212
self._queue_poll_thread = self._start_queue_poll_thread()
206213

207214
def _ensure_work_dir(self) -> None:
208215
self.work_directory.mkdir(parents=True, exist_ok=True)
209216

217+
def _get_config(self, config: Optional[JobExecutorConfig]) -> BatchSchedulerExecutorConfig:
218+
if config is None:
219+
return BatchSchedulerExecutorConfig()
220+
if isinstance(config, BatchSchedulerExecutorConfig):
221+
return config
222+
return BatchSchedulerExecutorConfig._from_config(config)
223+
210224
def submit(self, job: Job) -> None:
211225
"""See :func:`~psij.JobExecutor.submit`."""
212226
logger.info('Job %s: submitting', job.id)

0 commit comments

Comments
 (0)