Added refreshed since for channels
This commit is contained in:
parent
66a9c1edb4
commit
e11ddfa72c
@ -13,6 +13,15 @@ namespace YTManager.Controllers {
|
|||||||
[Produces("application/json")]
|
[Produces("application/json")]
|
||||||
[Route("api/Admin")]
|
[Route("api/Admin")]
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
|
// Get the mass update daemon job.
|
||||||
|
private static RecurringJobDto get_massupdatedaemon() {
|
||||||
|
return Hangfire.JobStorage
|
||||||
|
.Current
|
||||||
|
.GetConnection()
|
||||||
|
.GetRecurringJobs()
|
||||||
|
.SingleOrDefault(j => j.Id == Mass_Updater_ID);
|
||||||
|
}
|
||||||
|
|
||||||
// ID for mass update job, used to tell if the job is running or not.
|
// ID for mass update job, used to tell if the job is running or not.
|
||||||
public static string Mass_Updater_ID { get; } = "2013066213";
|
public static string Mass_Updater_ID { get; } = "2013066213";
|
||||||
|
|
||||||
@ -36,9 +45,12 @@ namespace YTManager.Controllers {
|
|||||||
// Ensures that the background YT Channel update API is running.
|
// Ensures that the background YT Channel update API is running.
|
||||||
[HttpPost("Start_Updater")]
|
[HttpPost("Start_Updater")]
|
||||||
public IActionResult Start_Updater() {
|
public IActionResult Start_Updater() {
|
||||||
|
if (get_massupdatedaemon() == null) {
|
||||||
Hangfire.RecurringJob.AddOrUpdate(
|
Hangfire.RecurringJob.AddOrUpdate(
|
||||||
Mass_Updater_ID,
|
Mass_Updater_ID,
|
||||||
() => Tasks.FetchVideos.MassUpdate(Startup.DBStr), Hangfire.Cron.Hourly);
|
() => Tasks.FetchVideos.MassUpdate(Startup.DBStr), Hangfire.Cron.Minutely);
|
||||||
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +58,7 @@ namespace YTManager.Controllers {
|
|||||||
// Check if the periodic update job is enqued.
|
// Check if the periodic update job is enqued.
|
||||||
[HttpGet("Update")]
|
[HttpGet("Update")]
|
||||||
public IActionResult Get_Update_Status() {
|
public IActionResult Get_Update_Status() {
|
||||||
bool exists = Hangfire.JobStorage.Current.GetConnection().GetRecurringJobs().Any(j => j.Id == Mass_Updater_ID);
|
return Ok(get_massupdatedaemon() == null ? "false" : "true");
|
||||||
return Ok(exists ? "true" : "false");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
102
YTManager/Migrations/20180220053952_added_refreshed.Designer.cs
generated
Normal file
102
YTManager/Migrations/20180220053952_added_refreshed.Designer.cs
generated
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.Internal;
|
||||||
|
using System;
|
||||||
|
using YTManager;
|
||||||
|
|
||||||
|
namespace YTManager.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(MediaDB))]
|
||||||
|
[Migration("20180220053952_added_refreshed")]
|
||||||
|
partial class added_refreshed
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn)
|
||||||
|
.HasAnnotation("ProductVersion", "2.0.1-rtm-125");
|
||||||
|
|
||||||
|
modelBuilder.Entity("YTManager.Models.Channel", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("PrimaryKey")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<DateTime>("AddedtoDB");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<DateTime>("Refreshed");
|
||||||
|
|
||||||
|
b.Property<string>("ThumbnailURL")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<string>("YoutubeID")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasKey("PrimaryKey");
|
||||||
|
|
||||||
|
b.ToTable("Channels");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("YTManager.Models.Tag", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("PrimaryKey")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasKey("PrimaryKey");
|
||||||
|
|
||||||
|
b.ToTable("Tags");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("YTManager.Models.Video", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("PrimaryKey")
|
||||||
|
.ValueGeneratedOnAdd();
|
||||||
|
|
||||||
|
b.Property<DateTime>("AddedToYT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("AddedtoDB");
|
||||||
|
|
||||||
|
b.Property<long?>("ChannelPrimaryKey");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<string>("ThumbnailURL")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<string>("YoutubeID")
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasKey("PrimaryKey");
|
||||||
|
|
||||||
|
b.HasIndex("ChannelPrimaryKey");
|
||||||
|
|
||||||
|
b.ToTable("Videos");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("YTManager.Models.Video", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("YTManager.Models.Channel")
|
||||||
|
.WithMany("Videos")
|
||||||
|
.HasForeignKey("ChannelPrimaryKey");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
25
YTManager/Migrations/20180220053952_added_refreshed.cs
Normal file
25
YTManager/Migrations/20180220053952_added_refreshed.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace YTManager.Migrations
|
||||||
|
{
|
||||||
|
public partial class added_refreshed : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "Refreshed",
|
||||||
|
table: "Channels",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Refreshed",
|
||||||
|
table: "Channels");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,8 @@ namespace YTManager.Migrations
|
|||||||
b.Property<string>("Description")
|
b.Property<string>("Description")
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Property<DateTime>("Refreshed");
|
||||||
|
|
||||||
b.Property<string>("ThumbnailURL")
|
b.Property<string>("ThumbnailURL")
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ namespace YTManager.Models {
|
|||||||
[Required]
|
[Required]
|
||||||
public DateTime AddedtoDB { get; set; }
|
public DateTime AddedtoDB { get; set; }
|
||||||
|
|
||||||
|
//! Last time this channel was updated.
|
||||||
|
[Required]
|
||||||
|
public DateTime Refreshed { get; set; }
|
||||||
|
|
||||||
// Videos this channel has.
|
// Videos this channel has.
|
||||||
public List<Video> Videos { get; set; }
|
public List<Video> Videos { get; set; }
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,8 @@ namespace YTManager.Tasks {
|
|||||||
Title = response.Items.First().Snippet.Title,
|
Title = response.Items.First().Snippet.Title,
|
||||||
ThumbnailURL = response.Items.First().Snippet.Thumbnails.Medium.Url,
|
ThumbnailURL = response.Items.First().Snippet.Thumbnails.Medium.Url,
|
||||||
YoutubeID = channelID,
|
YoutubeID = channelID,
|
||||||
AddedtoDB = DateTime.Now
|
AddedtoDB = DateTime.Now,
|
||||||
|
Refreshed = DateTime.MinValue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +69,12 @@ namespace YTManager.Tasks {
|
|||||||
var ops = new DbContextOptionsBuilder<MediaDB>();
|
var ops = new DbContextOptionsBuilder<MediaDB>();
|
||||||
ops.UseNpgsql(dbstr);
|
ops.UseNpgsql(dbstr);
|
||||||
|
|
||||||
// Get all the channels from the db.
|
// Get all the channels from the db that expired.
|
||||||
|
var threshold = DateTime.Now.Subtract(TimeSpan.FromSeconds(100));
|
||||||
var channel_ids = await
|
var channel_ids = await
|
||||||
(new MediaDB(ops.Options))
|
(new MediaDB(ops.Options)).Channels
|
||||||
.Channels.Select(ch => ch.YoutubeID)
|
.Where(ch => ch.Refreshed < threshold)
|
||||||
|
.Select(ch => ch.YoutubeID)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// For each channel, do an update.
|
// For each channel, do an update.
|
||||||
|
Loading…
Reference in New Issue
Block a user