Files
Umbraco-CMS/src/Umbraco.Infrastructure/Services/IDistributedJobService.cs
Nikolaj Geisle 20de48a496 Load Balancing: Implement distributed background jobs (#20397)
* Start work

* Introduce dto

* Start making repository

* Add migrations

* Implement fetchable first job

* Fix up to also finish tasks

* Refactor jobs to distributed background jobs

* Filter jobs correctly on LastRun

* Hardcode delay

* Add settings to configure delay and period

* Fix formatting

* Add default data

* Add update on startup, which will update periods on startup

* Refactor service to return job directly

* Update src/Umbraco.Infrastructure/Services/Implement/DistributedJobService.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update src/Umbraco.Infrastructure/BackgroundJobs/DistributedBackgroundJobHostedService.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Remove unused

* Move jobs and make internal

* make OpenIddictCleanupJob.cs public, as it is used elsewhere

* Minor docstring changes

* Update src/Umbraco.Core/Persistence/Constants-Locks.cs

Co-authored-by: Mole <nikolajlauridsen@protonmail.ch>

* ´Throw correct exceptions

* Update xml doc

* Remove business logic from repository

* Remove more business logic from repository into service

* Remove adding jobs from migration

* fix creation

* Rename to ExecuteAsync

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: mole <nikolajlauridsen@protonmail.ch>
2025-10-07 18:49:21 +02:00

36 lines
1.2 KiB
C#

using Umbraco.Cms.Infrastructure.BackgroundJobs;
namespace Umbraco.Cms.Infrastructure.Services;
/// <summary>
/// Service for managing distributed jobs.
/// </summary>
public interface IDistributedJobService
{
/// <summary>
/// Attempts to claim a runnable distributed job for execution.
/// </summary>
/// <returns>
/// The claimed <see cref="IDistributedBackgroundJob"/> if available, or <see langword="null"/> if no jobs are ready to run.
/// </returns>
Task<IDistributedBackgroundJob?> TryTakeRunnableAsync();
/// <summary>
/// Finishes a job.
/// </summary>
Task FinishAsync(string jobName);
/// <summary>
/// Ensures all distributed jobs are registered in the database on startup.
/// </summary>
/// <remarks>
/// This method handles two scenarios:
/// <list type="bullet">
/// <item><description>Fresh install: Adds all registered jobs to the database</description></item>
/// <item><description>Restart: Updates existing jobs where periods have changed and adds any new jobs</description></item>
/// </list>
/// Jobs that exist in the database but are no longer registered in code will be removed.
/// </remarks>
Task EnsureJobsAsync();
}