Skip to content

Commit

Permalink
we can reuse the experiment from above to avoid an API call
Browse files Browse the repository at this point in the history
  • Loading branch information
CamDavidsonPilon committed May 6, 2024
1 parent 97ccfb2 commit 8b107f5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
### Upcoming
- Chart legend's will support more than 8 Pioreactors.
- UI performance improvements.
- Upgraded to React 18
- Removed unused dependencies
- App performance improvements
- Upgrade paho-mqtt to 2.0
- faster `pio kill`
- faster startup from UI

### 24.5.1

Expand Down
3 changes: 1 addition & 2 deletions pioreactor/background_jobs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,13 @@ def __post__init__(self) -> None:
P.ready()
C.on_ready()
"""
self.set_state(self.READY)

with JobManager() as jm:
self._jm_key = jm.register_and_set_running(
self.unit, self.experiment, self.job_name, self._job_source, getpid(), leader_hostname
)

self.set_state(self.READY)

def start_passive_listeners(self) -> None:
# overwrite this to in subclasses to subscribe to topics in MQTT
# using this handles reconnects correctly.
Expand Down
11 changes: 8 additions & 3 deletions pioreactor/background_jobs/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:
self.logger.debug(f"Running `{job_name}` from monitor job.")

else:
command = self._job_options_and_args_to_shell_command(job_name, args, options)
command = self._job_options_and_args_to_shell_command(
job_name, assigned_experiment, args, options
)
Thread(
target=subprocess.run,
args=(command,),
Expand All @@ -703,10 +705,13 @@ def run_job_on_machine(self, msg: MQTTMessage) -> None:

@staticmethod
def _job_options_and_args_to_shell_command(
job_name: str, args: list[str], options: dict[str, Any]
job_name: str, experiment: str, args: list[str], options: dict[str, Any]
) -> str:
core_command = ["pio", "run", job_name]
env = [f'JOB_SOURCE={options.pop("job_source", "user")}']

# job source could be experiment_profile, but defaults to user
# we actually can skip another API request by reusing the assigned experiment above...
env = [f'JOB_SOURCE={options.pop("job_source", "user")}', f"EXPERIMENT='{experiment}'"]

list_of_options: list[str] = []
for option, value in options.items():
Expand Down
1 change: 0 additions & 1 deletion pioreactor/whoami.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def get_assigned_experiment_name(unit_name: str) -> str:

def _get_assigned_experiment_name(unit_name: str) -> str:
from pioreactor.logging import create_logger
from pioreactor import mureq

if os.environ.get("EXPERIMENT") is not None:
return os.environ["EXPERIMENT"]
Expand Down

0 comments on commit 8b107f5

Please sign in to comment.