# OpsAlertsService

**Kind:** Service

**Source:** [`atloria-monorepo/apps/api/src/ops/ops-alerts.service.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/ops/ops-alerts.service.ts#L23)

`OpsAlertsService` is a NestJS backend service responsible for running operational alert evaluation through its `sweep()` method. It fits into the operations domain as a reusable service that can be invoked by scheduled jobs, controllers, or other backend workflows to detect and process alert conditions.

## Methods

| Method | Signature | Returns |
|---|---|---|
| `sweep` | `sweep()` | `unknown` |

## Dependencies

- `PrismaService`
- `EmailService`

## Where it refuses work

- `OpsAlertsService` stops the work with an early return when `!to.length`.

## Diagram

```mermaid
sequenceDiagram
  participant Scheduler as Scheduler / Caller
  participant Alerts as OpsAlertsService
  participant Sources as Operational Data Sources
  participant AlertsSink as Alert Delivery / Storage

  Scheduler->>Alerts: sweep()
  Alerts->>Sources: Read operational state
  Sources-->>Alerts: Metrics / events / status data
  Alerts->>Alerts: Evaluate alert conditions
  Alerts->>AlertsSink: Record or dispatch alerts
  AlertsSink-->>Alerts: Result
  Alerts-->>Scheduler: Sweep completes
```

## Usage

```ts
import { Injectable } from '@nestjs/common';
import { OpsAlertsService } from './ops-alerts.service';

@Injectable()
export class OpsMonitoringJob {
  constructor(private readonly opsAlertsService: OpsAlertsService) {}

  async run(): Promise<void> {
    await this.opsAlertsService.sweep();
  }
}
```

## AI Coding Instructions

- Keep alert-evaluation logic centralized in `OpsAlertsService.sweep()` rather than duplicating it in controllers, jobs, or consumers.
- Treat `sweep()` as an asynchronous operational workflow; always `await` it and ensure callers handle failures appropriately.
- When adding alert checks, make them idempotent so repeated sweeps do not create duplicate notifications or records.
- Integrate scheduled execution through the NestJS scheduling layer or an existing job runner rather than introducing ad hoc timers.

## Relationships

- DEPENDS_ON → `PrismaService`
- DEPENDS_ON → `EmailService`

## Referenced By

- `OpsModule` (MODULE_PROVIDES)
