2023-03-31 23:00:15 -07:00
|
|
|
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
|
|
|
|
{
|
2023-04-01 08:53:34 -07:00
|
|
|
ConnectionString = _connectionStrings.Database,
|
|
|
|
OpenTelemetry = _connectionStrings.OpenTelemetry,
|
|
|
|
IsEnabled = _rssConfig.IsEnabled
|
2023-03-31 23:00:15 -07:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost("check/youtube")]
|
|
|
|
public void CheckYoutube()
|
|
|
|
{
|
|
|
|
BackgroundJob.Enqueue<YoutubeWatcherJob>(x => x.InitAndExecute(new YoutubeWatcherJobOptions
|
|
|
|
{
|
|
|
|
ConnectionStrings = _connectionStrings
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|