From a99af43ff00c22ebab589c39414d6018b4be394b Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Sat, 2 Nov 2024 10:22:08 -0700 Subject: [PATCH] Fix watchdog factory default --- .../launcher/behavior_launcher.py | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/aind_behavior_experiment_launcher/launcher/behavior_launcher.py b/src/aind_behavior_experiment_launcher/launcher/behavior_launcher.py index 812de62..b1e36fe 100644 --- a/src/aind_behavior_experiment_launcher/launcher/behavior_launcher.py +++ b/src/aind_behavior_experiment_launcher/launcher/behavior_launcher.py @@ -1,5 +1,6 @@ from __future__ import annotations +import datetime import glob import logging import os @@ -181,6 +182,9 @@ def _pre_run_hook(self, *args, **kwargs) -> Self: self.session_schema.experiment = self.task_logic_schema.name self.session_schema.experiment_version = self.task_logic_schema.version + if self.services_factory_manager.data_transfer is not None: + if not self.services_factory_manager.data_transfer.validate(): + raise ValueError("Data transfer service failed validation.") if self.services_factory_manager.bonsai_app.layout is None: self.services_factory_manager.bonsai_app.layout = ( self.services_factory_manager.bonsai_app.prompt_visualizer_layout_input(self.config_library_dir) @@ -338,21 +342,32 @@ def _aind_data_mapper_factory(launcher: BehaviorLauncher) -> AindDataSchemaSessi def watchdog_data_transfer_factory( - watchdog: WatchdogDataTransferService, + *, + destination: os.PathLike, + schedule_time: Optional[datetime.time] = datetime.time(hour=20), + project_name: Optional[str] = None, + **watchdog_kwargs, ) -> Callable[[BehaviorLauncher], WatchdogDataTransferService]: - return partial(_watchdog_data_transfer_factory, watchdog=watchdog) + return partial( + _watchdog_data_transfer_factory, + destination=destination, + schedule_time=schedule_time, + project_name=project_name, + **watchdog_kwargs, + ) -def _watchdog_data_transfer_factory( - launcher: BehaviorLauncher, watchdog: WatchdogDataTransferService -) -> WatchdogDataTransferService: +def _watchdog_data_transfer_factory(launcher: BehaviorLauncher, **watchdog_kwargs) -> WatchdogDataTransferService: if launcher.services_factory_manager.data_mapper is None: raise ValueError("Data mapper service is not set. Cannot create watchdog.") if not isinstance(launcher.services_factory_manager.data_mapper, AindDataSchemaSessionDataMapper): raise ValueError( "Data mapper service is not of the correct type (AindDataSchemaSessionDataMapper). Cannot create watchdog." ) - watchdog.aind_data_mapper = launcher.services_factory_manager.data_mapper + watchdog = WatchdogDataTransferService( + source=launcher.session_directory, + aind_data_mapper=launcher.services_factory_manager.data_mapper, + **watchdog_kwargs) return watchdog