Newsbot.Collector/Newsbot.Collector.Api/Controllers/JobsController.cs

47 lines
1.5 KiB
C#
Raw Normal View History

using Hangfire;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Newsbot.Collector.Database.Repositories;
using Newsbot.Collector.Domain.Interfaces;
using Newsbot.Collector.Domain.Models.Config;
using Newsbot.Collector.Services.Jobs;
namespace Newsbot.Collector.Api.Controllers;
[ApiController]
[Route("api/jobs")]
public class JobsController
{
private readonly ConfigSectionConnectionStrings _connectionStrings;
private readonly ConfigSectionRssModel _rssConfig;
private readonly ILogger<SourcesController> _logger;
private readonly ISourcesRepository _sources;
public JobsController(ILogger<SourcesController> logger, IOptions<ConfigSectionConnectionStrings> connectionStrings,
IOptions<ConfigSectionRssModel> rss)
{
_logger = logger;
_connectionStrings = connectionStrings.Value;
_rssConfig = rss.Value;
_sources = new SourcesTable(connectionStrings.Value.Database ?? "");
}
[HttpPost("check/rss")]
public void CheckReddit()
{
BackgroundJob.Enqueue<RssWatcherJob>(x => x.InitAndExecute(new RssWatcherJobOptions
{
ConnectionStrings = _connectionStrings,
Config = _rssConfig
}));
}
[HttpPost("check/youtube")]
public void CheckYoutube()
{
BackgroundJob.Enqueue<YoutubeWatcherJob>(x => x.InitAndExecute(new YoutubeWatcherJobOptions
{
ConnectionStrings = _connectionStrings
}));
}
}