app / src /ClipForge.Infrastructure /Services /SchedulerService.cs
Vanderson da Silva Quintino
fix: pipeline runs full job in background
35a656e
Raw History Blame Contribute Delete
1.84 kB
using ClipForge.Core.Interfaces.Services;
using Hangfire;
using Microsoft.Extensions.Logging;
namespace ClipForge.Infrastructure.Services;
public class SchedulerService : ISchedulerService
{
private readonly IRecurringJobManager _recurringJobs;
private readonly IBackgroundJobClient _backgroundJobs;
private readonly ILogger<SchedulerService> _logger;
public SchedulerService(
IBackgroundJobClient backgroundJobs,
IRecurringJobManager recurringJobs,
ILogger<SchedulerService> logger)
{
_backgroundJobs = backgroundJobs;
_recurringJobs = recurringJobs;
_logger = logger;
}
public Task ScheduleFullPipelineAsync(string niche, string platform = "tiktok", CancellationToken ct = default)
{
_logger.LogInformation("Scheduling full pipeline for niche '{Niche}' on {Platform}", niche, platform);
// Handled directly in PipelineEndpoints via Hangfire
return Task.CompletedTask;
}
public Task ScheduleRecurringGenerationAsync(string niche, string cronExpression, string platform = "tiktok", CancellationToken ct = default)
{
var jobId = $"pipeline-{niche}-{platform}".ToLowerInvariant().Replace(" ", "-");
_logger.LogInformation("Scheduling recurring pipeline '{JobId}' with cron '{Cron}'", jobId, cronExpression);
_recurringJobs.AddOrUpdate<IIdeaGenerationService>(
jobId,
svc => svc.GenerateIdeaAsync(niche, platform, CancellationToken.None),
cronExpression);
return Task.CompletedTask;
}
public Task CancelRecurringJobAsync(string jobId, CancellationToken ct = default)
{
_logger.LogInformation("Cancelling recurring job '{JobId}'", jobId);
_recurringJobs.RemoveIfExists(jobId);
return Task.CompletedTask;
}
}