Vanderson da Silva Quintino commited on
Commit
35a656e
·
1 Parent(s): 468499f

fix: pipeline runs full job in background

Browse files
src/ClipForge.Api/Endpoints/PipelineEndpoints.cs CHANGED
@@ -11,10 +11,10 @@ public static class PipelineEndpoints
11
  {
12
  var group = app.MapGroup("/api/pipeline").WithTags("Pipeline");
13
 
14
- // Run full pipeline immediately (background job)
15
- group.MapPost("/run", async (FullPipelineRequest request, ISchedulerService scheduler) =>
16
  {
17
- await scheduler.ScheduleFullPipelineAsync(request.Niche, request.Platform);
18
  return Results.Accepted(value: new { Message = "Pipeline scheduled", Niche = request.Niche, Platform = request.Platform });
19
  });
20
 
 
11
  {
12
  var group = app.MapGroup("/api/pipeline").WithTags("Pipeline");
13
 
14
+ // Run full pipeline in background (Hangfire)
15
+ group.MapPost("/run", (FullPipelineRequest request, IBackgroundJobClient backgroundJobs) =>
16
  {
17
+ backgroundJobs.Enqueue<FullPipelineJob>(job => job.ExecuteAsync(request.Niche, request.Platform, "francisca"));
18
  return Results.Accepted(value: new { Message = "Pipeline scheduled", Niche = request.Niche, Platform = request.Platform });
19
  });
20
 
src/ClipForge.Infrastructure/Services/SchedulerService.cs CHANGED
@@ -6,8 +6,8 @@ namespace ClipForge.Infrastructure.Services;
6
 
7
  public class SchedulerService : ISchedulerService
8
  {
9
- private readonly IBackgroundJobClient _backgroundJobs;
10
  private readonly IRecurringJobManager _recurringJobs;
 
11
  private readonly ILogger<SchedulerService> _logger;
12
 
13
  public SchedulerService(
@@ -23,17 +23,13 @@ public class SchedulerService : ISchedulerService
23
  public Task ScheduleFullPipelineAsync(string niche, string platform = "tiktok", CancellationToken ct = default)
24
  {
25
  _logger.LogInformation("Scheduling full pipeline for niche '{Niche}' on {Platform}", niche, platform);
26
-
27
- // Enqueue using IIdeaGenerationService as entry point - the pipeline endpoint handles orchestration
28
- _backgroundJobs.Enqueue<IIdeaGenerationService>(svc => svc.GenerateIdeaAsync(niche, platform, CancellationToken.None));
29
-
30
  return Task.CompletedTask;
31
  }
32
 
33
  public Task ScheduleRecurringGenerationAsync(string niche, string cronExpression, string platform = "tiktok", CancellationToken ct = default)
34
  {
35
  var jobId = $"pipeline-{niche}-{platform}".ToLowerInvariant().Replace(" ", "-");
36
-
37
  _logger.LogInformation("Scheduling recurring pipeline '{JobId}' with cron '{Cron}'", jobId, cronExpression);
38
 
39
  _recurringJobs.AddOrUpdate<IIdeaGenerationService>(
 
6
 
7
  public class SchedulerService : ISchedulerService
8
  {
 
9
  private readonly IRecurringJobManager _recurringJobs;
10
+ private readonly IBackgroundJobClient _backgroundJobs;
11
  private readonly ILogger<SchedulerService> _logger;
12
 
13
  public SchedulerService(
 
23
  public Task ScheduleFullPipelineAsync(string niche, string platform = "tiktok", CancellationToken ct = default)
24
  {
25
  _logger.LogInformation("Scheduling full pipeline for niche '{Niche}' on {Platform}", niche, platform);
26
+ // Handled directly in PipelineEndpoints via Hangfire
 
 
 
27
  return Task.CompletedTask;
28
  }
29
 
30
  public Task ScheduleRecurringGenerationAsync(string niche, string cronExpression, string platform = "tiktok", CancellationToken ct = default)
31
  {
32
  var jobId = $"pipeline-{niche}-{platform}".ToLowerInvariant().Replace(" ", "-");
 
33
  _logger.LogInformation("Scheduling recurring pipeline '{JobId}' with cron '{Cron}'", jobId, cronExpression);
34
 
35
  _recurringJobs.AddOrUpdate<IIdeaGenerationService>(
src/ClipForge.Infrastructure/Services/VideoAssemblyService.cs CHANGED
@@ -68,13 +68,13 @@ public class VideoAssemblyService : IVideoAssemblyService
68
 
69
  var backgroundClips = new List<string>();
70
 
71
- // Use the first 2-3 most specific scene descriptions as search queries
72
- var searchQueries = scenes.Take(3).ToList();
73
 
74
  foreach (var query in searchQueries)
75
  {
76
- if (backgroundClips.Count >= 8) break;
77
- var neededPerQuery = Math.Max(3, (8 - backgroundClips.Count));
78
  var clips = await _stockMedia.DownloadMultipleVideosAsync(query, neededPerQuery, tempDir, ct);
79
  backgroundClips.AddRange(clips);
80
  }
 
68
 
69
  var backgroundClips = new List<string>();
70
 
71
+ // Use the first 2 most specific scene descriptions as search queries
72
+ var searchQueries = scenes.Take(2).ToList();
73
 
74
  foreach (var query in searchQueries)
75
  {
76
+ if (backgroundClips.Count >= 4) break;
77
+ var neededPerQuery = Math.Max(2, (4 - backgroundClips.Count));
78
  var clips = await _stockMedia.DownloadMultipleVideosAsync(query, neededPerQuery, tempDir, ct);
79
  backgroundClips.AddRange(clips);
80
  }