# `sc_crawler.inspector_rules`

> Rules for which servers and managed databases the Inspector runs its tasks on.

# `sc_crawler.inspector_rules`

**Functions:**

- [**has_related_database**](#has_related_database) – Check if the server is the underlying server of any Database of the same Vendor.
- [**is_credit_exempt**](#is_credit_exempt) – Check if the task should run on the resource despite exhausted cloud credits.
- [**block_reasons**](#block_reasons) – Check in a deterministic way if the resource should run the given inspector task(s).

## func <code class="doc-name">has_related_database</code> [inspector_rules.py:65–76](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/inspector_rules.py#L65-L76)

```python
has_related_database(server)
```

Check if the server is the underlying server of any Database of the same Vendor.

**Parameters:**

- **server** ([`Server`](https://docs.sparecores.com/crawler/reference/tables.md#server)) – The server to look up in the `server_id` of the Vendor's Databases.

**Returns:**

- [`bool`](https://docs.python.org/3/builtins/functions.html#bool) – True if at least one Database of the Vendor references the server.

## func <code class="doc-name">is_credit_exempt</code> [inspector_rules.py:79–98](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/inspector_rules.py#L79-L98)

```python
is_credit_exempt(resource, task)
```

Check if the task should run on the resource despite exhausted cloud credits.

**Parameters:**

- **resource** ([`Server`](https://docs.sparecores.com/crawler/reference/tables.md#server) | [`Database`](https://docs.sparecores.com/crawler/reference/tables.md#database)) – The server or managed database.
- **task** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of an inspector task.

**Returns:**

- [`bool`](https://docs.python.org/3/builtins/functions.html#bool) – True if the cloud credit block reason doesn't apply.

## func <code class="doc-name">block_reasons</code> [inspector_rules.py:101–219](https://github.com/SpareCores/sc-crawler/blob/81bb61ea164dda526de4aa6de298810007274f21/src/sc_crawler/inspector_rules.py#L101-L219)

```python
block_reasons(resource, tasks)
```

Check in a deterministic way if the resource should run the given inspector task(s).

Lists of inspector tasks defined at https://github.com/SpareCores/sc-inspector/blob/main/inspector/tasks.py

A task doesn't run on a resource for any of these reasons:

- All tasks:
    - Cloud credits or budget exhausted: Alibaba Cloud, Azure and GCP,
      except for a few explicitly exempted resources and tasks (see
      `is_credit_exempt`).

- Managed databases:
    - Databases that can't be deployed on a single node.

- Servers:
    - `bw_mem` and `membench`: a few servers with identified performance issues while running this task.
    - `nvidia_smi` and `nvbandwidth`: servers without GPUs.
    - Not enough memory: `membench` needs 0.9 GB; `compression_text`, `ffmpeg` and `llm` 1 GB; `vllm` and `pgbench_postgres_ro_durable` 2 GB; `geekbench` 2.1 GB.
    - `vllm`: fewer than 2 vCPUs (server and GuideLLM contend for the single core; no successful measurements observed).
    - `geekbench` and `passmark`: more than 32 vCPUs, as they don't scale beyond that.
    - `storage`: no bundled storage.
    - `stressnglongrun`: explicit allowlist for a few small AWS, GCP and Hetzner Cloud server types.

**Parameters:**

- **resource** ([`Server`](https://docs.sparecores.com/crawler/reference/tables.md#server) | [`Database`](https://docs.sparecores.com/crawler/reference/tables.md#database)) – The server or managed database.
- **tasks** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`List`](https://docs.python.org/3/library/typing.html#typing.List)`[`[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)`]`) – Name of an inspector task, or a list of them.

**Returns:**

- [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)`[`[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`List`](https://docs.python.org/3/library/typing.html#typing.List)`[`[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)`]]` – The reasons per task, with an empty list for a task that can run.
