CrazyIter 4 年之前
父节点
当前提交
5e7891e5fb
共有 3 个文件被更改,包括 10 次插入3 次删除
  1. 2 1
      CMS/CMS.csproj
  2. 7 2
      CMS/Services/DataETLService.cs
  3. 1 0
      CMS/Startup.cs

+ 2 - 1
CMS/CMS.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.Web">
+<Project Sdk="Microsoft.NET.Sdk.Web">
 
   <PropertyGroup>
     <TargetFramework>netcoreapp3.1</TargetFramework>
@@ -13,6 +13,7 @@
     <PackageReference Include="BCrypt.Net-Core" Version="1.6.0" />
     <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.2.0" />
     <PackageReference Include="MySql.Data" Version="8.0.20" />
+    <PackageReference Include="Pomelo.AspNetCore.TimedJob" Version="2.0.0-rtm-10046" />
     <PackageReference Include="Serilog" Version="2.9.0" />
     <PackageReference Include="sqlSugarCore" Version="5.0.0.10" />
     <PackageReference Include="System.Drawing.Common" Version="4.7.0" />

+ 7 - 2
CMS/Services/DataETLService.cs

@@ -1,6 +1,7 @@
 using CMS.Context;
 using CMS.Models.Source;
 using CMS.Models.Target;
+using Pomelo.AspNetCore.TimedJob;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -44,8 +45,12 @@ namespace CMS.Services
         {
             return targetService.Insert(targetExercises);
         }
-
-        
+        /// <summary>
+        /// Begin 起始时间;Interval执行时间间隔,单位是毫秒,建议使用以下格式,此处为6小时;
+        /// SkipWhileExecuting是否等待上一个执行完成,true为等待;
+        /// </summary>
+        /// <param name="services"></param>
+        [Invoke(Begin = "2018-09-21 00:00", Interval = 1000 * 60 * 60 * 1, SkipWhileExecuting = true)]
         public bool ETL() {
             List<SourceExercise> sourceExercises=  ExtractData();
 

+ 1 - 0
CMS/Startup.cs

@@ -36,6 +36,7 @@ namespace CMS
                .AddClasses(classes => classes.AssignableTo<IBusinessService>())
                    .AsSelfWithInterfaces()
                    .WithScopedLifetime());
+            services.AddTimedJob();
         }
 
         // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.