Skip to content

Resource

CLASS DESCRIPTION
Resource

Resource table.

Classes

Resource

Bases: SQLModel

Resource table.

ATTRIBUTE DESCRIPTION
host

Address for ssh connections, when type="slurm_ssh".

TYPE: str | None

jobs_local_dir

Base local folder for job subfolders (containing artifacts and logs).

TYPE: str

jobs_poll_interval

On SLURM resources: the interval to wait before new squeue calls.

TYPE: int

jobs_runner_config

Runner configuration, matching one of JobRunnerConfigLocal or

TYPE: dict[str, Any]

jobs_slurm_python_worker

On SLURM deloyments, this is the Python interpreter that runs the

TYPE: str | None

name

Resource name.

TYPE: str

pip_cache_dir_arg

If pip_cache_dir is set (in self.tasks_python_config), then

TYPE: str

prevent_new_submissions

When set to true: Prevent new job submissions and stop execution of

TYPE: bool

tasks_local_dir

Base local folder for task-package subfolders.

TYPE: str

tasks_pixi_config

Pixi configuration for task collection. Basic example:

TYPE: dict[str, Any]

tasks_python_config

Python configuration for task collection. Example:

TYPE: dict[str, Any]

timestamp_created

Creation timestamp (autogenerated).

TYPE: datetime

type

One of local, slurm_sudo or slurm_ssh - matching with

TYPE: str

Source code in fractal_server/app/models/v2/resource.py
class Resource(SQLModel, table=True):
    """
    Resource table.
    """

    id: int | None = Field(default=None, primary_key=True)

    type: str
    """
    One of `local`, `slurm_sudo` or `slurm_ssh` - matching with
    `settings.FRACTAL_RUNNER_BACKEND`.
    """

    name: str = Field(unique=True)
    """
    Resource name.
    """

    timestamp_created: datetime = Field(
        default_factory=get_timestamp,
        sa_column=Column(DateTime(timezone=True), nullable=False),
    )
    """
    Creation timestamp (autogenerated).
    """

    host: str | None = None
    """
    Address for ssh connections, when `type="slurm_ssh"`.
    """

    prevent_new_submissions: bool = Field(
        sa_column=Column(
            BOOLEAN,
            server_default="false",
            nullable=False,
        ),
    )
    """
    When set to true: Prevent new job submissions and stop execution of
    ongoing jobs as soon as the current task is complete.
    """

    jobs_local_dir: str
    """
    Base local folder for job subfolders (containing artifacts and logs).
    """

    jobs_runner_config: dict[str, Any] = Field(
        sa_column=Column(JSONB, nullable=False, server_default="{}")
    )
    """
    Runner configuration, matching one of `JobRunnerConfigLocal` or
    `JobRunnerConfigSLURM` schemas.
    """

    jobs_slurm_python_worker: str | None = None
    """
    On SLURM deloyments, this is the Python interpreter that runs the
    `fractal-server` worker from within the SLURM jobs.
    """

    jobs_poll_interval: int
    """
    On SLURM resources: the interval to wait before new `squeue` calls.
    On local resources: ignored.
    """

    # task_settings
    tasks_local_dir: str
    """
    Base local folder for task-package subfolders.
    """

    tasks_python_config: dict[str, Any] = Field(
        sa_column=Column(JSONB, nullable=False, server_default="{}")
    )
    """
    Python configuration for task collection. Example:
    ```json
    {
      "default_version": "3.10",
      "versions:{
        "3.10": "/xxx/venv-3.10/bin/python",
        "3.11": "/xxx/venv-3.11/bin/python",
        "3.12": "/xxx/venv-3.12/bin/python"
       }
    }
    ```
    """

    tasks_pixi_config: dict[str, Any] = Field(
        sa_column=Column(JSONB, nullable=False, server_default="{}")
    )
    """
    Pixi configuration for task collection. Basic example:
    ```json
    {
        "default_version": "0.41.0",
        "versions": {
            "0.40.0": "/xxx/pixi/0.40.0/",
            "0.41.0": "/xxx/pixi/0.41.0/"
        },
    }
    ```
    """

    @property
    def pip_cache_dir_arg(self: Self) -> str:
        """
        If `pip_cache_dir` is set (in `self.tasks_python_config`), then
        return `--cache_dir /something`; else return `--no-cache-dir`.
        """
        _pip_cache_dir = self.tasks_python_config.get("pip_cache_dir", None)
        if _pip_cache_dir is not None:
            return f"--cache-dir {_pip_cache_dir}"
        else:
            return "--no-cache-dir"

    # Check constraints
    __table_args__ = (
        # `type` column must be one of "local", "slurm_sudo" or "slurm_ssh"
        CheckConstraint(
            "type IN ('local', 'slurm_sudo', 'slurm_ssh')",
            name="correct_type",
        ),
        # If `type` is not "local", `jobs_slurm_python_worker` must be set
        CheckConstraint(
            "(type = 'local') OR (jobs_slurm_python_worker IS NOT NULL)",
            name="jobs_slurm_python_worker_set",
        ),
    )

Attributes

host = None class-attribute instance-attribute

Address for ssh connections, when type="slurm_ssh".

jobs_local_dir instance-attribute

Base local folder for job subfolders (containing artifacts and logs).

jobs_poll_interval instance-attribute

On SLURM resources: the interval to wait before new squeue calls. On local resources: ignored.

jobs_runner_config = Field(sa_column=(Column(JSONB, nullable=False, server_default='{}'))) class-attribute instance-attribute

Runner configuration, matching one of JobRunnerConfigLocal or JobRunnerConfigSLURM schemas.

jobs_slurm_python_worker = None class-attribute instance-attribute

On SLURM deloyments, this is the Python interpreter that runs the fractal-server worker from within the SLURM jobs.

name = Field(unique=True) class-attribute instance-attribute

Resource name.

pip_cache_dir_arg property

If pip_cache_dir is set (in self.tasks_python_config), then return --cache_dir /something; else return --no-cache-dir.

prevent_new_submissions = Field(sa_column=(Column(BOOLEAN, server_default='false', nullable=False))) class-attribute instance-attribute

When set to true: Prevent new job submissions and stop execution of ongoing jobs as soon as the current task is complete.

tasks_local_dir instance-attribute

Base local folder for task-package subfolders.

tasks_pixi_config = Field(sa_column=(Column(JSONB, nullable=False, server_default='{}'))) class-attribute instance-attribute

Pixi configuration for task collection. Basic example:

{
    "default_version": "0.41.0",
    "versions": {
        "0.40.0": "/xxx/pixi/0.40.0/",
        "0.41.0": "/xxx/pixi/0.41.0/"
    },
}

tasks_python_config = Field(sa_column=(Column(JSONB, nullable=False, server_default='{}'))) class-attribute instance-attribute

Python configuration for task collection. Example:

{
  "default_version": "3.10",
  "versions:{
    "3.10": "/xxx/venv-3.10/bin/python",
    "3.11": "/xxx/venv-3.11/bin/python",
    "3.12": "/xxx/venv-3.12/bin/python"
   }
}

timestamp_created = Field(default_factory=get_timestamp, sa_column=(Column(DateTime(timezone=True), nullable=False))) class-attribute instance-attribute

Creation timestamp (autogenerated).

type instance-attribute

One of local, slurm_sudo or slurm_ssh - matching with settings.FRACTAL_RUNNER_BACKEND.

Functions: