Appearance
Configuration
GrydJobsOptions
All GrydJobs settings are configured through GrydJobsOptions:
csharp
builder.Services.AddGrydJobs(options =>
{
// ... configuration here
});Connection String
Required. PostgreSQL connection string used by both Hangfire storage and EF Core job metadata. This is one configured service-level connection; GrydJobs does not switch Hangfire or metadata storage to a different database for each tenant. Tenant identity is captured in job envelopes and restored for execution and tenant-scoped row access.
csharp
options.ConnectionString = "Host=localhost;Database=gryd_jobs;...";Queues
Defines the queue names the Hangfire server polls and the worker counts used to size its shared worker pool. Jobs can be assigned to these queues when they are submitted. Queue order is provider configuration; the PostgreSQL provider does not guarantee that the first listed queue has priority.
csharp
options.Queues =
[
new QueueOptions { Name = "critical", WorkerCount = 4 },
new QueueOptions { Name = "default", WorkerCount = 10 },
new QueueOptions { Name = "low", WorkerCount = 2 }
];
// Default: critical (4), default (10), and low (2)The configured worker counts are summed for the server's shared worker pool. They do not reserve workers for individual queues. The server can only execute jobs in queues listed here, so include every queue used by job submissions, retries, and dead-letter replays.
For immediate and replayed jobs, GrydJobs stores the requested queue with the Hangfire job and uses it for the initial Enqueued state. Delayed jobs begin in Scheduled and continuations begin in Awaiting; both keep the requested queue in the Hangfire job, and a continuation uses that queue for its next Enqueued state. The delayed scheduler uses the stored job queue when a scheduled job becomes runnable, including scheduled retries. Recurring registrations keep their configured queue for each tick.
An explicit non-default queue on a provider enqueued state is a deliberate routing override and determines that execution's queue metadata. The trusted scheduling envelope continues to record the queue originally requested by GrydJobs. When a retry moves through Scheduled, the delayed scheduler routes from the stored Hangfire job queue, so execution metadata is refreshed to that queue when the job starts again.
Worker Count
Set WorkerCount on each queue entry. The values are added to size the shared worker pool.
csharp
options.Queues =
[
new QueueOptions { Name = "default", WorkerCount = 20 }
];Auto-Register Recurring Jobs
When enabled, scans JobAssemblies at startup for IRecurringJob implementations.
csharp
options.AutoRegisterRecurringJobs = true; // Default: true
options.JobAssemblies = [typeof(MyJob).Assembly];Dead Letter Retention
Number of days to retain dead letter entries before automatic cleanup.
csharp
options.DeadLetterRetentionDays = 30; // Default: 30
// Set to null to disable automatic cleanupRetry Policies
Default Policy
Applied to all jobs without a specific policy:
csharp
options.DefaultRetryPolicy = new RetryPolicyOptions
{
MaxRetries = 3,
BaseDelay = TimeSpan.FromSeconds(10),
MaxDelay = TimeSpan.FromMinutes(5),
BackoffType = BackoffType.Exponential
};Per-Job Policies
Override retry behavior for specific job types:
csharp
options.RetryPolicies
.Add<SendEmailJob>(new RetryPolicyOptions
{
MaxRetries = 5,
BaseDelay = TimeSpan.FromSeconds(30),
BackoffType = BackoffType.Exponential
})
.Add<ImportJob>(new RetryPolicyOptions
{
MaxRetries = 10,
BaseDelay = TimeSpan.FromMinutes(2),
BackoffType = BackoffType.Linear
});MaxRetries counts retries after the initial attempt: 3 means up to 4 executions. A submission's MaxRetries override wins over the configured per-type policy, which wins over the default. The effective policy is captured with the provider invocation, so later configuration changes apply to new submissions only. Hangfire durably schedules retries for GrydJobs adapters.
Execution deadlines
Jobs use DefaultTimeout unless a type-specific timeout is configured. Timeout cancellation is cooperative: jobs should pass the supplied token through their work and stop when it is cancelled. GrydJobs waits for the job task to finish before disposing the scope or allowing another attempt. A job that ignores cancellation can delay its retry; it is not abandoned into background work. Provider shutdown cancellation does not consume retry budget.
csharp
options.DefaultTimeout = TimeSpan.FromMinutes(5);
options.Timeouts[typeof(LongRunningJob)] = TimeSpan.FromMinutes(30);Backoff Types
| Type | Description |
|---|---|
Fixed | Same delay between each retry |
Linear | Delay increases linearly (delay × attempt) |
Exponential | Delay doubles each attempt (delay × 2^attempt) |
Producer and executor hosts
By default one process enqueues and runs jobs. To split them, call services.SetGrydHostRole(GrydHostRole.Producer) on the host that only enqueues and schedules, and leave the host that runs jobs as Executor (or All). On a Producer host AddGrydJobsInfrastructure registers the Hangfire client and no BackgroundJobServer, and neither the dead-letter cleanup nor the lifecycle reconciliation loop starts; both hosts share the Hangfire database, so a job enqueued on the producer runs on the executor. See Background tenancy.
Audit trail of job operations
Every write route of the job controllers (enqueue, cancel, create/update/delete/pause/resume/trigger a recurring job, retry or purge the dead letter) carries [JobOperationAudit]. After the route answers 2xx it records one entry through the shared IAuditStore: entity type JobOperation, entity id the route id (the controller name when the route has none), action jobs.<operation> (jobs.cancelled, jobs.recurring_triggered, jobs.dead_letter_purged, ...), actor the session's user id. A platform operation files under no tenant; an organization's cancel under the session's tenant. The entry holds no payload, e-mail or address. A host without the Audit module gets the null store and keeps nothing. A 4xx records nothing. If the write fails the operation has already happened: the failure is logged with the ids and the caller gets a 500, so nobody takes it for recorded. AddGrydJobsApi registers the catalog contributor, so the actions are labelled in en-US, pt-BR and es-ES.
Health Checks
Register health checks to monitor job infrastructure:
csharp
builder.Services.AddGrydJobsHealthChecks(
name: "grydjobs",
failureStatus: HealthStatus.Degraded,
tags: ["grydjobs", "background-jobs"]);The health check verifies:
- Background job servers are running
- Server heartbeats are recent (< 5 minutes)
Dashboard
The embedded Hangfire dashboard provides real-time monitoring:
csharp
app.UseGrydJobsDashboard(pathMatch: "/grydjobs/dashboard");Dashboard features:
- Real-time job processing stats
- Queue depths and throughput
- Recurring job schedules
- Failed job inspection
- Built-in retry from dashboard
Access requires authentication (integrated with ASP.NET Core Identity).