File size: 2,028 Bytes
8fb6238
 
 
 
 
 
 
 
 
 
 
 
 
35a656e
 
8fb6238
35a656e
8fb6238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using ClipForge.Contracts.Requests;
using ClipForge.Core.Interfaces.Services;
using ClipForge.Workers.Jobs;
using Hangfire;

namespace ClipForge.Api.Endpoints;

public static class PipelineEndpoints
{
    public static void MapPipelineEndpoints(this WebApplication app)
    {
        var group = app.MapGroup("/api/pipeline").WithTags("Pipeline");

        // Run full pipeline in background (Hangfire)
        group.MapPost("/run", (FullPipelineRequest request, IBackgroundJobClient backgroundJobs) =>
        {
            backgroundJobs.Enqueue<FullPipelineJob>(job => job.ExecuteAsync(request.Niche, request.Platform, "francisca"));
            return Results.Accepted(value: new { Message = "Pipeline scheduled", Niche = request.Niche, Platform = request.Platform });
        });

        // Schedule recurring pipeline
        group.MapPost("/schedule", async (SchedulePipelineRequest request, ISchedulerService scheduler) =>
        {
            if (string.IsNullOrEmpty(request.CronExpression))
                return Results.BadRequest(new { Error = "CronExpression is required for scheduling" });

            await scheduler.ScheduleRecurringGenerationAsync(request.Niche, request.CronExpression, request.Platform);
            return Results.Ok(new { Message = "Recurring pipeline scheduled", Niche = request.Niche, Cron = request.CronExpression });
        });

        // Cancel recurring job
        group.MapDelete("/schedule/{jobId}", async (string jobId, ISchedulerService scheduler) =>
        {
            await scheduler.CancelRecurringJobAsync(jobId);
            return Results.Ok(new { Message = $"Job '{jobId}' cancelled" });
        });

        // Run full pipeline synchronously (for testing)
        group.MapPost("/run-sync", async (FullPipelineRequest request, FullPipelineJob job) =>
        {
            await job.ExecuteAsync(request.Niche, request.Platform, request.VoiceId);
            return Results.Ok(new { Message = "Pipeline completed", Niche = request.Niche });
        });
    }
}