---
id: scheduler-service
name: Scheduler Service
version: 1.0.0
summary: |
  Single-host Quartz.NET job execution engine and operational dashboard UI
  for scheduling recurring platform jobs and inspecting execution history.
styles:
  icon: /icons/languages/dotnet.svg
owners:
  - platform-engineering-team
badges:
  - content: Internal
    backgroundColor: gray
    textColor: gray
  - content: Operations
    backgroundColor: yellow
    textColor: yellow
sends:
  - id: ProcessVectorBatchIntegrationEvent
    version: 1.0.0
    group: Catalog Maintenance
    to:
      - id: scheduler.process-vector-batch
        version: 1.0.0
readsFrom:
  - id: scheduler-database
    version: 1.0.0
writesTo:
  - id: scheduler-database
    version: 1.0.0
specifications:
  - type: asyncapi
    path: asyncapi-v1.yml
    name: AsyncAPI V1
repository:
  language: C#
  url: "https://github.com/foxminchan/BookWorm"
---

## Service Responsibility & Boundary

Scheduler Service is the Quartz.NET job host and paired administrative dashboard within the [[domain|platform]] domain that manages durable UTC cron schedules, emits liveness heartbeats, and dispatches recurring catalog vector ingestion triggers over Kafka. It persists schedules and 30-day execution history in [[container|scheduler-database]], while delegating actual vector indexing to [[service|catalog-ingestion]].

## Service Profile

| Property                                  | Value                                                                                                                |
| :---------------------------------------- | :------------------------------------------------------------------------------------------------------------------- |
| **Bounded Context / Domain**              | [[domain\|platform]]                                                                                                 |
| **Owner Team**                            | [[team\|platform-engineering-team]]                                                                                  |
| **Runtime Style**                         | Scheduled Job Host & Administrative Dashboard UI                                                                     |
| **Public / Gateway Exposure**             | Admin UI exposed via OIDC; job host is Internal Only (not routed via API Gateway)                                    |
| **Authentication & Authorization Policy** | Microsoft Entra ID OIDC requiring the `admin` app role for the operator dashboard; internal worker for job execution |
| **Owned Data Store(s)**                   | [[container\|scheduler-database]] (Quartz schedule state, 30-day execution history, and transactional outbox)        |
| **Key Resilience / Idempotency Pattern**  | Non-concurrent job execution, durable misfire recovery (`FireOnceNow`), and transactional outbox publishing          |

## Contracts & Data Ownership

Scheduler Service owns schedule definitions, trigger state, and execution history in [[container|scheduler-database]]. Every five minutes UTC, it publishes [[event|ProcessVectorBatchIntegrationEvent]] to [[channel|scheduler.process-vector-batch]] via its transactional outbox for [[service|catalog-ingestion]] to consume.

:::note
A successful job firing proves only that the trigger event was dispatched—not that downstream indexing completed. Operators should inspect pending vector update counts in [[container|catalog-database]] alongside [[service|catalog-ingestion]] logs when diagnosing search lag.
:::

:::warning
Never store credentials, authorization headers, notification bodies, or personal data in Quartz job metadata or trigger data maps.
:::

<MessageTable format="all" limit={10} showChannels={true} />

## Architecture Visualizations & Specifications

### Scheduler Host Context

<MermaidFileLoader file="mermaids/SchedulerDashboard-diagram-1.mmd" />

### Service Interactions

<NodeGraph />

## Attached Resources & Related Docs

- [[doc|platform/006-api-and-contracts]] — Consolidated service and messaging index.
- [[container|scheduler-database]] — Persistent storage for Quartz schedules and outbox.
- [[doc|platform/005-quartz-schema]] — Persistent Quartz table definitions.
- [[service|catalog-ingestion]] — Downstream worker consuming scheduled batch triggers.


 ## Raw Schema:asyncapi-v1.yml

asyncapi: 3.1.0
info:
  title: Scheduler integration events
  version: 1.0.0
  description: |
    Kafka integration contract for the BookWorm Scheduler host. A durable Quartz
    job publishes a vector-batch trigger event to Catalog Ingestion every five
    minutes in UTC (cron 0 0/5 * * * ?, misfire policy FireOnceNow). The job
    disallows concurrent executions and reports publication failures to Quartz
    as JobExecutionException.

    Payload schemas describe the camelCase JSON data inside BookWorm's
    CloudEvents-compatible envelope, not the complete transport envelope.
    HeartbeatJob writes logs only and does not publish a Kafka integration event.
defaultContentType: application/cloudevents+json
channels:
  processVectorBatch:
    address: scheduler.process-vector-batch
    description: Scheduler triggers Catalog Ingestion to process a bounded batch of pending vector updates.
    messages:
      processVectorBatch:
        $ref: "#/components/messages/ProcessVectorBatchIntegrationEvent"
operations:
  sendProcessVectorBatch:
    action: send
    channel:
      $ref: "#/channels/processVectorBatch"
    summary: Publish a five-minute catalog vector batch trigger
    description: |
      ProcessVectorBatchJob publishes this event through Wolverine. Catalog
      Ingestion consumes it via a Kafka-triggered Azure Function, acquires a
      PostgreSQL advisory lock, and processes up to 200 pending updates.
    messages:
      - $ref: "#/channels/processVectorBatch/messages/processVectorBatch"
components:
  messages:
    ProcessVectorBatchIntegrationEvent:
      name: ProcessVectorBatchIntegrationEvent
      title: Process catalog vector batch
      summary: Triggers Catalog Ingestion to process pending book embedding updates.
      description: "Wolverine message identity: BookWorm.Contracts.ProcessVectorBatchIntegrationEvent."
      contentType: application/json
      payload:
        $ref: "#/components/schemas/IntegrationEventPayload"
      examples:
        - name: processVectorBatchTrigger
          payload:
            id: "019a1c00-0000-7000-8000-000000000001"
            creationDate: "2026-11-17T00:05:00Z"
  schemas:
    IntegrationEventPayload:
      type: object
      additionalProperties: false
      required:
        - id
        - creationDate
      properties:
        id:
          type: string
          format: uuid
          description: Unique identifier of the integration event.
        creationDate:
          type: string
          format: date-time
          description: UTC timestamp when the event was created.
