Skip to content

Commit

Permalink
Added ability to specify default jobdef path and type if not given in…
Browse files Browse the repository at this point in the history
… command (#68)
  • Loading branch information
natsunlee committed Mar 7, 2024
1 parent e8e5e77 commit b7cc7e6
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions flowmancer/flowmancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ def __init__(self, *, test: bool = False, debug: bool = False) -> None:
self._synchro_interval_seconds = 0.25
self._is_restart = False

def start(self) -> int:
def start(self, default_jobdef_path: Optional[str] = None, default_jobdef_type: str = 'yaml') -> int:
orig_cwd = os.getcwd()
try:
# Ensure any components, such as file loggers, work with respect to the .py file in which the `start`
# command is invoked, which is usually the project root dir.
app_root_dir = os.path.dirname(os.path.abspath(inspect.stack()[-1][1]))
os.chdir(app_root_dir)
if not self._test:
self._process_cmd_args(orig_cwd, app_root_dir)
self._process_cmd_args(orig_cwd, app_root_dir, default_jobdef_path, default_jobdef_type)
if not self._executors:
raise NoTasksLoadedError(
'No Tasks have been loaded! Please check that you have provided a valid Job Definition file.'
Expand Down Expand Up @@ -153,10 +153,16 @@ def _validate_checkpoint(self, checkpoint: CheckpointContents) -> None:
msg += 'f\n * {n}'
raise CheckpointInvalidError('Task names in Checkpoint do not match registered task names:')

def _process_cmd_args(self, caller_cwd: str, app_root_dir: str) -> None:
def _process_cmd_args(
self,
caller_cwd: str,
app_root_dir: str,
default_jobdef_path: Optional[str] = None,
default_jobdef_type: str = 'yaml'
) -> None:
parser = ArgumentParser(description='Flowmancer job execution options.')
parser.add_argument('-j', '--jobdef', action='store', dest='jobdef')
parser.add_argument('-t', '--type', action='store', dest='jobdef_type', default='yaml')
parser.add_argument('-j', '--jobdef', action='store', dest='jobdef', default=default_jobdef_path)
parser.add_argument('-t', '--type', action='store', dest='jobdef_type', default=default_jobdef_type)
parser.add_argument('-r', '--restart', action='store_true', dest='restart', default=False)
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False)
parser.add_argument('--skip', action='append', dest='skip', default=[])
Expand Down

0 comments on commit b7cc7e6

Please sign in to comment.