SubmittedImageCleaningService
Namespace: Commissiestrijd.Data
Assembly: backend.dll
Service for cleaning up old submitted images. This service runs in the background and periodically checks for submitted tasks that are older than a year and have an associated image. It deletes the image files and clears the image path in the database. The service is designed to run at midnight every day. It uses a background service to perform the cleanup operation asynchronously.
public class SubmittedImageCleaningService : BackgroundService, IHostedService, IDisposable
Inheritance
object
← BackgroundService
← SubmittedImageCleaningService
Implements
IDisposable
Show Inherited Members (12)
Constructors
SubmittedImageCleaningService(IServiceProvider, ILogger<SubmittedImageCleaningService>)
Initializes a new instance of the SubmittedImageCleaningService class. This constructor is used to set up the service with the provided service provider and logger.
public SubmittedImageCleaningService(IServiceProvider serviceProvider, ILogger<SubmittedImageCleaningService> logger)
Parameters
Name | Type |
---|---|
serviceProvider | IServiceProvider |
logger | ILogger<SubmittedImageCleaningService> |
Methods
ExecuteAsync(CancellationToken)
Executes the background service. This method runs in a loop, waiting until midnight to perform the cleanup operation. It retrieves all submitted tasks that are older than a year and have an associated image, deletes the image files from the filesystem, and clears the image path in the database. The service handles exceptions during the cleanup process and logs any errors encountered. The cleanup operation is performed asynchronously to avoid blocking the main thread.
protected override Task ExecuteAsync(CancellationToken stoppingToken)
Parameters
Name | Type |
---|---|
stoppingToken | CancellationToken |
Returns
Type |
---|
Task |