Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/madsci_common/madsci/common/types/workcell_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from madsci.common.types.workflow_types import AliasChoices, Workflow
from madsci.common.utils import new_ulid_str
from madsci.common.validators import ulid_validator
from pydantic import Field, computed_field
from pydantic import Field, ImportString, computed_field
from pydantic.functional_validators import field_validator
from pydantic.networks import AnyUrl
from pydantic_settings import SettingsConfigDict
Expand Down Expand Up @@ -275,11 +275,31 @@ class WorkcellManagerSettings(
title="Cold Start Delay",
description="How long the Workcell engine should sleep on startup",
)
scheduler: str = Field(
default="madsci.workcell_manager.schedulers.default_scheduler",
title="scheduler",
description="Scheduler module that contains a Scheduler class that inherits from AbstractScheduler to use",
scheduler: ImportString = Field(
default="madsci.workcell_manager.schedulers.default_scheduler:Scheduler",
title="Scheduler",
description=(
"Scheduler class to use, as a 'module:ClassName' import path "
"(e.g. 'madsci.workcell_manager.schedulers.default_scheduler:Scheduler'). "
"Must inherit from AbstractScheduler."
),
)

@field_validator("scheduler", mode="before")
@classmethod
def _handle_legacy_scheduler_string(cls, v: object) -> object:
"""Accept old bare-module strings and rewrite them to module:ClassName form."""
if isinstance(v, str) and ":" not in v:
warnings.warn(
f"Scheduler config '{v}' uses the legacy bare-module format. "
f"Use '{v}:Scheduler' instead. "
"Bare-module scheduler strings will be removed in a future version.",
DeprecationWarning,
stacklevel=2,
)
return f"{v}:Scheduler"
return v

document_db_url: Optional[AnyUrl] = Field(
default=AnyUrl("mongodb://localhost:27017"),
title="Document Database URL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import concurrent
import importlib
import time
from datetime import datetime
from typing import Optional, Union
Expand Down Expand Up @@ -68,8 +67,7 @@ def __init__(
self.workcell_info = state_handler.get_workcell_info()
self.logger = EventClient(name=f"workcell.{self.workcell_info.name}")
cancel_active_workflows(state_handler)
scheduler_module = importlib.import_module(self.workcell_settings.scheduler)
self.scheduler = scheduler_module.Scheduler(
self.scheduler = self.workcell_settings.scheduler(
self.workcell_info, self.state_handler
)
self.data_client = data_client
Expand Down