Learn.VideoAnalysis/VideoAnalysisCore/Job/NodePackageJob.cs

82 lines
3.1 KiB
C#

using AlibabaCloud.SDK.Vod20170321;
using Coravel.Invocable;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http.Json;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using UserCenter.Model.Enum;
using VideoAnalysisCore.Common;
using VideoAnalysisCore.Model;
using VideoAnalysisCore.Model.Dto;
using VideoAnalysisCore.Model.;
using Yitter.IdGenerator;
namespace VideoAnalysisCore.Job
{
/// <summary>
/// [蓝鲸智库] 查找文件包未处理的视频
/// </summary>
public class NodePackageJob : IInvocable
{
/// <summary>
/// 每个扫描文件包每次取出{20}个
/// </summary>
private readonly int TopLength = 20;
private readonly Repository<NodePackageInfo> nodePackageInfoDB;
private readonly Repository<Attachments> attachmentsDB;
private readonly Repository<VideoTask> videoTaskDB;
public NodePackageJob(Repository<Attachments> videoTaskDB,
Repository<NodePackageInfo> nodePackageInfoDB, Repository<VideoTask> videotaskDB)
{
this.attachmentsDB = videoTaskDB;
this.nodePackageInfoDB = nodePackageInfoDB;
this.videoTaskDB = videotaskDB;
}
public async Task Invoke()
{
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务");
var taskArr = await nodePackageInfoDB.AsQueryable()
.Where(s => s.SuccessTime == null)
.ToArrayAsync();
var videoIdArr = await videoTaskDB.AsQueryable()
.Where(s => s.EndTime != null)
.Select(s => s.TagId)
.ToArrayAsync();
var postData = new List<NodePackageInfo>();
foreach (var item in taskArr)
{
if (videoIdArr.Contains(item.VideoCode))
{
postData.Add(item);
item.SuccessTime = DateTime.Now;
}
}
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 已完成任务回调 数量{postData.Count}");
if (postData.Count() == 0)
return;
var responseMessage = await new HttpClient()
.PostAsJsonAsync(AppCommon.Config.Subsystem..APIUrl + "/api/callback/platform/videosAnalyze", postData);
if (responseMessage.IsSuccessStatusCode)
{
var res = await responseMessage.Content.ReadAsStringAsync();
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调结果 {res}");
await nodePackageInfoDB.AsUpdateable(postData)
.UpdateColumns(it => new { it.SuccessTime })
.ExecuteCommandAsync();
}
else
{
var res = await responseMessage.Content.ReadAsStringAsync();
Console.WriteLine($"{DateTime.Now} 执行=>文件包任务 回调失败!!! {responseMessage.StatusCode} {res}");
}
}
}
}