Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ export default defineConfig({
{ text: 'Overview', link: '/api-reference/configuration/core-configuration' },
{ text: 'Scheduler', link: '/api-reference/configuration/core-configuration/scheduler-configuration' },
{ text: 'Exception Handling', link: '/api-reference/configuration/core-configuration/exception-handling' },
{ text: 'Start Mode', link: '/api-reference/configuration/core-configuration/start-mode' }
{ text: 'Start Mode', link: '/api-reference/configuration/core-configuration/start-mode' },
{ text: 'Background Services', link: '/api-reference/configuration/core-configuration/background-services' }
]
},
{
Expand Down
4 changes: 4 additions & 0 deletions docs/api-reference/configuration/core-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Set up global exception handlers for job execution errors.
### [Start Mode](./core-configuration/start-mode)
Control when TickerQ starts processing jobs.

### [Background Services](./core-configuration/background-services)
Enable or disable background job processing services for queue-only mode.

## Quick Example

```csharp
Expand All @@ -35,5 +38,6 @@ builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
- [Scheduler Configuration](./core-configuration/scheduler-configuration) - Detailed scheduler options
- [Exception Handling](./core-configuration/exception-handling) - Global exception handler setup
- [Start Mode](./core-configuration/start-mode) - Application startup control
- [Background Services](./core-configuration/background-services) - Enable or disable background processing
- [Configuration Overview](./index) - All configuration sections

Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Background Services

Control whether TickerQ registers and runs background job processing services.

## DisableBackgroundServices

Disable registration of background services for queue-only mode.

**Method:**
```csharp
TickerOptionsBuilder<TTimeTicker, TCronTicker> DisableBackgroundServices();
```

**Example:**
```csharp
builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
{
// Only register managers for queuing jobs, no processing
options.DisableBackgroundServices();
});
```

## Background Services

By default, TickerQ registers the following background services:

| Service | Purpose |
|---------|---------|
| `TickerQSchedulerBackgroundService` | Main scheduler for job execution |
| `TickerQFallbackBackgroundService` | Fallback job checking mechanism |
| `TickerQDispatcher` | Dispatches jobs to worker threads |
| `TickerQTaskScheduler` | Manages worker thread pool |

When `DisableBackgroundServices()` is called, these services are replaced with no-operation implementations that do not process jobs.

## Queue-Only Mode

When background services are disabled, TickerQ operates in "queue-only" mode:

- **Available**: `ITimeTickerManager` and `ICronTickerManager` for queuing jobs
- **Available**: `ITickerQHostScheduler` (no-op implementation)
- **Available**: `ITickerQDispatcher` (no-op implementation, `IsEnabled = false`)
- **Not Available**: Actual job processing and execution

Jobs queued in this mode will be stored (in-memory or database) but won't execute until processed by an application with background services enabled.

## Use Cases

### Web API for Job Queuing Only

Run a lightweight API server that only queues jobs, with separate worker instances processing them:

```csharp
// API Server - queue-only mode
builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
{
options.DisableBackgroundServices();
});

// Worker Server - with processing
builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
{
// Default: background services enabled
options.ConfigureScheduler(scheduler =>
{
scheduler.MaxConcurrency = 20;
});
});
```

### Microservices Architecture

Separate job creation from job processing across different services:

```csharp
// Order Service - creates jobs, doesn't process
builder.Services.AddTickerQ<OrderTimeTicker, OrderCronTicker>(options =>
{
options.DisableBackgroundServices();
});

// Worker Service - processes jobs
builder.Services.AddTickerQ<OrderTimeTicker, OrderCronTicker>(options =>
{
options.ConfigureScheduler(scheduler =>
{
scheduler.NodeIdentifier = "order-worker-01";
});
});
```

### Testing Scenarios

Queue jobs without executing them during tests:

```csharp
services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
{
options.DisableBackgroundServices();
});

// Jobs can be queued and verified without execution
await timeTickerManager.AddAsync(new TTimeTicker
{
Function = "TestFunction",
ExecutionTime = DateTime.UtcNow
});
```

## Behavior Details

### Dispatcher Behavior

When background services are disabled:

```csharp
var dispatcher = serviceProvider.GetRequiredService<ITickerQDispatcher>();

// Returns false - dispatcher is not functional
Console.WriteLine(dispatcher.IsEnabled); // false

// DispatchAsync is a no-op
await dispatcher.DispatchAsync(contexts); // Does nothing
```

### Scheduler Behavior

When background services are disabled:

```csharp
var scheduler = serviceProvider.GetRequiredService<ITickerQHostScheduler>();

// Always returns false
Console.WriteLine(scheduler.IsRunning); // false

// Start/Stop are no-ops
await scheduler.StartAsync(); // Does nothing
await scheduler.StopAsync(); // Does nothing
```

### Manager Behavior

Managers work normally regardless of background services setting:

```csharp
var timeManager = serviceProvider.GetRequiredService<ITimeTickerManager<TTimeTicker>>();

// Works normally - job is persisted
await timeManager.AddAsync(new TTimeTicker
{
Function = "MyFunction",
ExecutionTime = DateTime.UtcNow.AddHours(1)
});

// Job won't execute locally, but will be processed by nodes with background services enabled
```

## Combining with Other Options

```csharp
builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
{
// Disable background services
options.DisableBackgroundServices();

// Exception handler still works for manager operations
options.SetExceptionHandler<MyExceptionHandler>();

// Seeding still works
options.UseTickerSeeder(
async timeManager => { /* seed time tickers */ },
async cronManager => { /* seed cron tickers */ }
);
});
```

## See Also

- [Start Mode](./start-mode) - Control when processing starts
- [Scheduler Configuration](./scheduler-configuration) - Worker thread settings
- [Core Configuration Overview](./index) - All core configuration options
4 changes: 4 additions & 0 deletions docs/api-reference/configuration/core-configuration/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Set up global exception handlers for job execution errors.
### [Start Mode](./start-mode)
Control when TickerQ starts processing jobs.

### [Background Services](./background-services)
Enable or disable background job processing services for queue-only mode.

### Request Serialization
Control how ticker request payloads are serialized and stored (plain JSON bytes or GZip-compressed).

Expand Down Expand Up @@ -71,4 +74,5 @@ builder.Services.AddTickerQ<TTimeTicker, TCronTicker>(options =>
- [Scheduler Configuration](./scheduler-configuration) - Detailed scheduler options
- [Exception Handling](./exception-handling) - Global exception handler setup
- [Start Mode](./start-mode) - Application startup control
- [Background Services](./background-services) - Enable or disable background processing
- [Configuration Overview](../index) - All configuration sections