Skip to content

Commit

Permalink
allow for flags
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed Sep 14, 2023
1 parent 5d76c5a commit c41180b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,14 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:
"options": {
"option_A": "value1",
"option_B": "value2"
"flag": None
},
"args": ["arg1", "arg2"]
}
effectively runs:
> pio run job_name arg1 arg2 --option-A value1 --option-B value2
> pio run job_name arg1 arg2 --option-A value1 --option-B value2 --flag
"""

Expand Down Expand Up @@ -639,15 +640,18 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:

list_of_options: list[str] = []
for option, value in options.items():
list_of_options.extend([f"--{option.replace('_', '-')}", str(value)])
list_of_options.append(f"--{option.replace('_', '-')}")
if value is not None:
# this handles flag arguments, like --dry-run
list_of_options.append(str(value))

suffix = ">/dev/null 2>&1 &"

# shell-escaped to protect against injection vulnerabilities, see join docs
# we don't escape the suffix.
command = prefix + " " + join(core_command + args + list_of_options) + " " + suffix

self.logger.debug(f"Running `{command}` from Monitor job.")
self.logger.debug(f"Running `{command}` from monitor job.")

Thread(
target=subprocess.run,
Expand Down

0 comments on commit c41180b

Please sign in to comment.