How yuzd/hangfire.httpjob works
Main Components
• Server Component (Hangfire.HttpJob):
– Contains the primary Hangfire integration with HTTP job scheduling.
– Hosts the dashboard and API endpoints (for adding background and recurring jobs via HTTP POST requests).
– Manages the HTTP job dispatch, configuration (including authentication using basic auth), and job processing logic.
– Includes UI elements (JavaScript and CSS) for the dashboard and visual reports.
• Agent Component (Hangfire.HttpJob.Agent):
– Offers extensions to quickly develop and execute job programs.
– Contains multiple submodules for different storage backends (MSSQL, MySQL, PostgreSQL, Redis). Each “console” project is tailored to a specific backend.
– Provides support for different job lifecycles (singleton, transient, and “hang until stop,” which is reflected in the custom attributes).
– Implements logging, heartbeat monitoring, and agent-specific utilities to help integrate the job processes with Hangfire.
• Client Component (Hangfire.HttpJob.Client):
– Provides a library for external consumers to submit jobs via code.
– Contains methods for constructing and sending background job payloads, recurring job payloads, and handling responses.
Interaction and Relationships
• External Consumers/Application Layer:
– Uses the Client to interact with the Hangfire server, calling methods to add or remove jobs.
– Can interact directly via RESTful API endpoints on the server as described in the README.
• Server and Dashboard:
– The server hosts the HTTP API endpoints and a dashboard (with dynamic CSS/JS for real-time updates, logging, cron generation, etc.).
– It manages job scheduling, processing, and dispatching on behalf of client requests.
– It communicates with and receives job execution requests from the Agent modules.
• Agent and Server Communication:
– Agent components plug into the Hangfire pipeline to execute jobs using different storage mechanics.
– They read configurations (from appsettings or job attributes) to decide how the job runs.
– Heartbeat and monitoring functionality is implemented in both Server and Agent, ensuring job status and health are visible on the dashboard.
Architectural Patterns and Technologies
• The system employs a modular, layered approach:
– Separating core processing (Server), specialized execution (Agent), and client interaction (Client) into distinct modules.
• It makes use of dependency injection (via .NET Core’s IServiceCollection) and configuration extension methods.
• The project uses Hangfire storage providers (e.g., MySQL, SQL Server, PostgreSQL, Redis) and offers flexibility to choose the appropriate database/storage.
• There’s a clear separation of concerns:
– The Server handles scheduling and dashboard UI.
– Agents are designed to support various back-end stores and provide extensible job execution.
– The Client abstracts the REST API calls, making integration simple for developers.
• The design emphasizes error handling, logging, and built-in support for notifying via email upon job execution completion.