增加定时调度入门

This commit is contained in:
大石头 2020-04-09 21:43:11 +08:00
parent de24b4e06c
commit b360158923
8 changed files with 92 additions and 6 deletions

View File

@ -31,7 +31,7 @@ namespace AntJob.Agent
/// </remarks>
protected override void StartWork(String reason)
{
var set = Setting.Current;
var set = AntSetting.Current;
// 实例化调度器
var sc = new Scheduler();

View File

@ -7,7 +7,7 @@ namespace AntJob
{
/// <summary>蚂蚁配置。主要用于网络型调度系统</summary>
[Config("Ant")]
public class Setting : Config<Setting>
public class AntSetting : Config<AntSetting>
{
#region
/// <summary>调试开关。默认false</summary>

View File

@ -91,7 +91,7 @@ namespace AntJob.Providers
var rs = await base.InvokeWithClientAsync<IDictionary<String, Object>>(client, "Login", arg);
var set = Setting.Current;
var set = AntSetting.Current;
if (set.Debug) XTrace.WriteLine("登录{0}成功!{1}", client, rs.ToJson());
// 保存下发密钥

View File

@ -11,7 +11,7 @@ namespace HelloWork
{
XTrace.UseConsole();
var set = Setting.Current;
var set = AntSetting.Current;
// 实例化调度器
var sc = new Scheduler();

View File

@ -0,0 +1,26 @@
using System;
using AntJob;
namespace HisAgent
{
internal class HelloJob : Handler
{
public HelloJob()
{
// 今天零点开始每10秒一次
var job = Job;
job.Start = DateTime.Today;
job.Step = 10;
}
protected override Int32 Execute(JobContext ctx)
{
// 当前任务时间
var time = ctx.Task.Start;
WriteLog("新生命蚂蚁调度系统!当前任务时间:{0}", time);
// 成功处理数据量
return 1;
}
}
}

View File

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>1.0.*</AssemblyVersion>
<Deterministic>false</Deterministic>
<OutputPath>..\..\Bin\HisAgent</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\AntJob\AntJob.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,37 @@
using System;
using AntJob;
using AntJob.Providers;
using NewLife.Log;
namespace HisAgent
{
class Program
{
static void Main(string[] args)
{
XTrace.UseConsole();
var set = AntSetting.Current;
// 实例化调度器
var sc = new Scheduler();
// 使用分布式调度引擎替换默认的本地文件调度
sc.Provider = new NetworkJobProvider
{
Server = set.Server,
AppID = set.AppID,
Secret = set.Secret,
};
// 添加作业处理器
sc.Handlers.Add(new HelloJob());
// 启动调度引擎,调度器内部多线程处理
sc.Start();
Console.WriteLine("OK!");
Console.ReadKey();
}
}
}

View File

@ -22,14 +22,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntJob.Extensions", "AntJob
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{E842807F-C45E-44DA-8AAE-7915C1EBF2A2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWork", "Samples\HelloWork\HelloWork.csproj", "{5E610811-2352-4882-ADD2-87222CCDE807}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelloWork", "Samples\HelloWork\HelloWork.csproj", "{5E610811-2352-4882-ADD2-87222CCDE807}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A1EF271C-AEA8-4EA3-A76F-906B4D4A9058}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AntJob.Agent", "AntJob.Agent\AntJob.Agent.csproj", "{0970FDBA-2331-4600-8DD5-A37B41AF989F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AntJob.Agent", "AntJob.Agent\AntJob.Agent.csproj", "{0970FDBA-2331-4600-8DD5-A37B41AF989F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HisAgent", "Samples\HisAgent\HisAgent.csproj", "{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -69,12 +71,17 @@ Global
{0970FDBA-2331-4600-8DD5-A37B41AF989F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0970FDBA-2331-4600-8DD5-A37B41AF989F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0970FDBA-2331-4600-8DD5-A37B41AF989F}.Release|Any CPU.Build.0 = Release|Any CPU
{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5E610811-2352-4882-ADD2-87222CCDE807} = {E842807F-C45E-44DA-8AAE-7915C1EBF2A2}
{E62006DC-E61B-42B0-A06B-ED5BF3F73D9E} = {E842807F-C45E-44DA-8AAE-7915C1EBF2A2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9337283C-C795-479F-A2F1-C892EBE2490C}