mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-23 10:16:36 +08:00
加入任务调度模块
This commit is contained in:
27
Yi.Framework/Yi.Framework.Task/HttpJob.cs
Normal file
27
Yi.Framework/Yi.Framework.Task/HttpJob.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Job
|
||||
{
|
||||
public class HttpJob : IJob
|
||||
{
|
||||
private ILogger<VisitJob> _logger;
|
||||
public HttpJob(ILogger<VisitJob> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Yi.Framework/Yi.Framework.Task/VisitJob.cs
Normal file
45
Yi.Framework/Yi.Framework.Task/VisitJob.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.ModelFactory;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Job
|
||||
{
|
||||
public class VisitJob : IJob
|
||||
{
|
||||
private ILogger<VisitJob> _logger;
|
||||
private DbContext _DBWrite;
|
||||
public VisitJob(ILogger<VisitJob> logger, IDbContextFactory DbFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_DBWrite = DbFactory.ConnWriteOrRead(Common.Enum.WriteAndReadEnum.Write);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应该将拜访清零,并且写入数据库中的拜访表中
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
||||
_DBWrite.Set<visit>().Add(new visit() { num = visitModel.visitNum, time = DateTime.Now });
|
||||
_DBWrite.SaveChanges();
|
||||
_logger.LogWarning("定时任务开始调度:" + nameof(VisitJob) + ":" + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + $":访问总数为:{visitModel.visitNum}");
|
||||
visitModel.visitNum = 0;
|
||||
}
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
Yi.Framework/Yi.Framework.Task/Yi.Framework.Job.csproj
Normal file
16
Yi.Framework/Yi.Framework.Task/Yi.Framework.Job.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Quartz.AspNetCore" Version="3.3.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Yi.Framework.Common\Yi.Framework.Common.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.Model\Yi.Framework.Model.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user