# Hangfire.SqlServer

**Kind:** Service

**Source:** `Pams/Logic/Pams.Business/Pams.Business.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`Hangfire.SqlServer` is a NuGet package dependency in `Pams.Business` that provides SQL Server-backed storage for Hangfire background jobs. It stores queued jobs, job state, and processing metadata so application workers can retrieve and execute work outside the request flow.

## Diagram

```mermaid
sequenceDiagram
    participant App as Pams Business
    participant Hangfire as Hangfire.SqlServer
    participant SqlServer as SQL Server Storage
    participant Worker as Background Worker

    App->>Hangfire: Enqueue background job
    Hangfire->>SqlServer: Persist job and state
    Worker->>SqlServer: Fetch queued job
    Worker->>Hangfire: Process job
    Hangfire->>SqlServer: Update job state
```

## Usage

```ts
// Hangfire runs on the server. Client code requests work through an API
// endpoint that queues a background job.

async function queueReport(reportId: string) {
  const response = await fetch("/api/reports/queue", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ reportId }),
  });

  if (!response.ok) {
    throw new Error("Unable to queue report generation.");
  }

  return response.json();
}

await queueReport("report-id");
```

## AI Coding Instructions

- Treat `Hangfire.SqlServer` as server-side infrastructure; browser code should request background work through an application API.
- Keep the SQL Server connection string in application configuration rather than source code.
- Follow the existing legacy project dependency declaration pattern when changing this package reference.
- Make background job handlers safe to run again because Hangfire can retry failed jobs.

## Used by

2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Injected or called by (2)

- `Pams.API` — `Pams/API/Pams.API/Pams.API.csproj`:1
- `Pams.Business` — `Pams/Logic/Pams.Business/Pams.Business.csproj`:1
