clabe.aind.watchdog ¶
UploadGroup ¶
Bases: BaseModel
One upload job of a session, written as its own watchdog manifest.
A session's modalities can be split into groups that are uploaded independently, e.g. to make the behavior data
available hours before its videos are compressed. All groups write to the same folder and asset: the group with
creates_record creates the asset's metadata record and the others append to it, so the job types must be set
up for that in the data transfer service.
The job_type, schedule_time, delete_modalities_source_after_success and upload_tasks fields of the
watchdog section are the shorthand for a single group with every modality.
WatchdogSettings ¶
Bases: ServiceSettings
Settings for the WatchdogDataTransferService.
Configures data transfer operations including destination paths, scheduling, and integration with the AIND watchdog service.
resolved_upload_groups ¶
resolved_upload_groups() -> list[UploadGroup]
The session's upload groups, the group that creates the record first.
Without upload_groups, a single group with every modality, from the deprecated single-job fields. It is
built on each call, so changes made to those fields after the settings are created apply. With
upload_groups, those fields are ignored, with a warning if any of them was set.
Source code in src/clabe/aind/watchdog.py
settings_customise_sources
classmethod
¶
settings_customise_sources(
settings_cls: type[BaseSettings],
init_settings: PydanticBaseSettingsSource,
env_settings: PydanticBaseSettingsSource,
dotenv_settings: PydanticBaseSettingsSource,
file_secret_settings: PydanticBaseSettingsSource,
) -> tuple[PydanticBaseSettingsSource, ...]
Customizes the settings sources to include the safe YAML settings source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings_cls
|
type[BaseSettings]
|
The settings class |
required |
init_settings
|
PydanticBaseSettingsSource
|
The initial settings source |
required |
env_settings
|
PydanticBaseSettingsSource
|
The environment settings source |
required |
dotenv_settings
|
PydanticBaseSettingsSource
|
The dotenv settings source |
required |
file_secret_settings
|
PydanticBaseSettingsSource
|
The file secret settings source |
required |
Returns:
| Type | Description |
|---|---|
tuple[PydanticBaseSettingsSource, ...]
|
Tuple[PydanticBaseSettingsSource, ...]: A tuple of settings sources |
Source code in src/clabe/settings.py
PlannedManifest
dataclass
¶
A manifest to write to the watchdog's flag directory.
Attributes:
| Name | Type | Description |
|---|---|---|
group |
str
|
Name of the upload group. |
creates_record |
bool
|
Whether the group creates the metadata record. |
filename |
str
|
The manifest's file name in the watchdog's flag directory. |
manifest |
ManifestConfig
|
The manifest. |
WatchdogDataTransferService ¶
WatchdogDataTransferService(
source: PathLike | None | Sequence[PathLike | None],
settings: WatchdogSettings,
session: Session,
*,
validate: bool = False,
email_from_experimenter_builder: Callable[[str], str]
| None = _default_email_from_experimenter,
)
Bases: DataTransfer[WatchdogSettings]
A data transfer service that uses the aind-watchdog-service to monitor and transfer data.
Integrates with the AIND data transfer infrastructure to automatically monitor directories for new data and transfer it to specified destinations with proper metadata handling and validation.
A session is written as one manifest per upload group (see WatchdogSettings.upload_groups).
Methods:
| Name | Description |
|---|---|
transfer |
Writes the session's manifests and starts the watchdog service |
plan |
Builds the session's manifests without writing them |
validate |
Validates the Watchdog service and its configuration |
is_valid_project_name |
Checks if the project name is valid |
is_running |
Checks if the Watchdog service is currently running |
force_restart |
Attempts to restart the Watchdog application |
dump_manifest_config |
Dumps the manifest configuration to a YAML file |
Initializes the WatchdogDataTransferService.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
PathLike | None | Sequence[PathLike | None]
|
The session folder(s) to transfer, e.g. |
required |
settings
|
WatchdogSettings
|
Configuration for the watchdog service |
required |
session
|
Session
|
The session data from aind-behavior-services |
required |
validate
|
bool
|
Whether to validate the project name |
False
|
email_from_experimenter_builder
|
Callable[[str], str] | None
|
Function to build email from experimenter name. Defaults to
looking up the email via Active Directory, raising |
_default_email_from_experimenter
|
Source code in src/clabe/aind/watchdog.py
settings
property
¶
Returns the settings for the data transfer service.
Returns:
| Name | Type | Description |
|---|---|---|
TSettings |
TSettings
|
The service settings |
transfer ¶
Writes the session's watchdog manifests, one per upload group, then starts the watchdog if needed.
The manifest of the group that creates the metadata record is written first, and nothing else is written if it fails. The manifests are written even if the service is not running, since it processes existing manifests when it starts; the service is then started if needed. Failing to start it is logged, never raised, since the manifests are already queued.
Source code in src/clabe/aind/watchdog.py
plan ¶
plan(
session: Session | None = None,
) -> list[PlannedManifest]
Builds the session's manifests, one per upload group, without writing them.
Each source is searched for folders named after a modality and for *.json metadata files. Each modality
goes to the group that claims it, or to the '*' group. Groups that find none of their modalities are
skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session | None
|
The session. Defaults to the service's. |
None
|
Returns:
| Type | Description |
|---|---|
list[PlannedManifest]
|
The manifests, the one of the group that creates the record first. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If a source cannot be reached. |
ValueError
|
If a modality is claimed by no group, the group that creates the record finds none of its modalities, or a group that appends is submitted before it. |
Source code in src/clabe/aind/watchdog.py
validate ¶
validate() -> bool
Validates the Watchdog service and its configuration.
Checks for required executables, configuration files, service status, and project name validity.
Returns:
| Type | Description |
|---|---|
bool
|
True if the service is valid, False otherwise |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If required files are missing |
HTTPError
|
If the project name validation fails |
Source code in src/clabe/aind/watchdog.py
is_valid_project_name ¶
is_valid_project_name() -> bool
Checks if the project name is valid by querying the metadata service.
Returns:
| Type | Description |
|---|---|
bool
|
True if the project name is valid, False otherwise |
Source code in src/clabe/aind/watchdog.py
add_data_description_tags ¶
add_data_description_tags(*tags: str) -> None
Registers tags to be added to the data description.
The tags are stored in the settings and written to the manifest of the group that creates the record when
it is built (i.e. on transfer). Duplicates are dropped when written.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tags
|
str
|
The tags to add |
()
|
is_running ¶
is_running() -> bool
Checks if the Watchdog service is currently running.
Returns:
| Type | Description |
|---|---|
bool
|
True if the service is running, False otherwise |
Source code in src/clabe/aind/watchdog.py
force_restart ¶
Attempts to restart the Watchdog application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kill_if_running
|
bool
|
Whether to terminate the service if it's already running |
True
|
Returns:
| Type | Description |
|---|---|
Popen[bytes]
|
A subprocess.Popen object representing the restarted service |
Source code in src/clabe/aind/watchdog.py
dump_manifest_config ¶
dump_manifest_config(
path: PathLike | None = None,
make_dir: bool = True,
manifest: ManifestConfig | None = None,
) -> Path
Dumps a manifest configuration to a YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathLike | None
|
The file path to save the manifest |
None
|
make_dir
|
bool
|
Whether to create the directory if it doesn't exist |
True
|
manifest
|
ManifestConfig | None
|
The manifest to dump. Defaults to the last one built by |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
The path to the saved manifest file |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the manifest or watch configuration is not set |