aind-watchdog-service

Module with Alert Bot for notifications on MS Teams

class aind_watchdog_service.alert_bot.AlertBot(url: str)[source]

Bases: object

Class to handle sending alerts and messages in MS Teams.

send_message(message: str, extra_text: str | None = None) Response | None[source]

Sends a message via requests.post

Parameters:
  • message (str) – The main message content

  • extra_text (Optional[str]) – Additional text to send in card body

Returns:

If the url is None, only print and return None. Otherwise, post message to url and return the response.

Return type:

Optional[requests.Response]

Event handler module

class aind_watchdog_service.event_handler.EventHandler(scheduler: BackgroundScheduler, config: WatchConfig)[source]

Bases: FileSystemEventHandler

Event handler for watchdog observer

on_created(event: FileCreatedEvent) None[source]

Event handler for file modified event

Parameters:

event (FileCreatedEvent) – file modified event

Return type:

None

on_deleted(event: FileCreatedEvent) None[source]

Event handler for file deleted event

Parameters:

event (FileCreatedEvent) – file deleted event

Return type:

None

schedule_job(event: FileCreatedEvent, job_config: ManifestConfig) None[source]

Schedule job to run

Parameters:
  • event (FileCreatedEvent) – event to trigger job

  • config (dict) – configuration for the job

Logging configuration

aind_watchdog_service.logging_config.setup_logging(log_file=None, log_level=20)[source]

Create log handler

Parameters:
  • log_file (filepath to send logging, optional) – by default None

  • log_level (configure logging level, optional) – by default logging.INFO

Main module to start the watchdog observer and scheduler

class aind_watchdog_service.main.WatchdogService(watch_config: WatchConfig, log_dir: Path = PosixPath('C:/ProgramData/aind/aind-watchdog-service'))[source]

Bases: object

Maintain and starts scheduler and observer

initiate_observer() None[source]

Starts Watchdog observer

initiate_scheduler() None[source]

Starts APScheduler

start_service() None[source]

Initiate scheduler and observer

aind_watchdog_service.main.main()[source]

Main function to parse arguments and start watchdog service

aind_watchdog_service.main.parse_args(args_list: list[str]) Namespace[source]

read in arguments from the command line

Parameters:

args_list (list[str]) – args read in by the command line

Returns:

parsed arguments

Return type:

argparse.Namespace

aind_watchdog_service.main.read_config(config_path: str) WatchConfig[source]

read yaml configuration file

Parameters:

config_path (str) – path to configuration file

Returns:

watchdog model

Return type:

WatchConfig

aind_watchdog_service.main.start_watchdog(watch_config: WatchConfig) None[source]

Load configuration, initiate WatchdogService and start service

Module to run jobs on file modification

class aind_watchdog_service.run_job.RunJob(event: FileCreatedEvent, config: ManifestConfig, watch_config: WatchConfig)[source]

Bases: object

Run job class to stage files on VAST or run a custom script and trigger aind-data-transfer-service

copy_to_vast() bool[source]

Determine platform and copy files to VAST

Returns:

status of the copy operation

Return type:

bool

execute_linux_command(src: str, dest: str) bool[source]

copy files using linux cp command

Parameters:
  • src (str) – source file or directory

  • dest (str) – destination directory

Returns:

True if copy was successful, False otherwise

Return type:

bool

execute_windows_command(src: str, dest: str) bool[source]

copy files using windows robocopy command

Parameters:
  • src (str) – source file or directory

  • dest (str) – destination directory

Returns:

True if copy was successful, False otherwise

Return type:

bool

move_manifest_to_archive() None[source]

Move manifest file to archive

run_job() None[source]

Triggers the vast transfer service

Parameters:

event (FileCreatedEvent) – modified event file

run_subprocess(cmd: list) CompletedProcess[source]

subprocess run command

Parameters:

cmd (list) – command to execute

Returns:

subprocess completed process

Return type:

subprocess.CompletedProcess

trigger_transfer_service() bool[source]

Triggers aind-data-transfer-service

init for watchdog service