From d18e5eec99924135b5c07b3057f19efd82249ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Mon, 18 Apr 2022 23:33:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Config/SwaggerDoc.xml | 12 +++++++ .../Controllers/TestController.cs | 34 ++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index de3a063a..6bf89910 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -93,5 +93,17 @@ + + + 启动一个定时任务,每5秒访问一次百度 + + + + + + 停止任务 + + + diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs index 873b8701..bec2e480 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs @@ -6,7 +6,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Yi.Framework.Common.Const; using Yi.Framework.Common.Models; +using Yi.Framework.Core; using Yi.Framework.Interface; using Yi.Framework.Language; using Yi.Framework.Model.Models; @@ -24,12 +26,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers private IStringLocalizer _local; private IUserService _iUserService; private IRoleService _iRoleService; + private QuartzInvoker _quartzInvoker; //你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来! - public TestController(ILogger logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer local) + public TestController(ILogger logger, IRoleService iRoleService, IUserService iUserService, IStringLocalizer local, QuartzInvoker quartzInvoker) { _local = local; _iUserService = iUserService; _iRoleService = iRoleService; + _quartzInvoker = quartzInvoker; } /// @@ -144,5 +148,33 @@ namespace Yi.Framework.ApiMicroservice.Controllers { return Result.Success().SetData(await _iUserService.GetListInRole()); } + + /// + /// 启动一个定时任务 + /// + /// + [HttpGet] + //每5秒访问一次百度,可查看控制台 + public async Task JobTest() + { + Dictionary data = new Dictionary() + { + {JobConst.method,"get" }, + {JobConst.url,"https://www.baidu.com" } + }; + await _quartzInvoker.start("*/5 * * * * ?", new Quartz.JobKey("test", "my"), "Yi.Framework.Job", "HttpJob", data: data); + return Result.Success(); + } + + /// + /// 停止任务 + /// + /// + [HttpPut] + public async Task stopJob() + { + await _quartzInvoker.Stop(new Quartz.JobKey("test", "my")); + return Result.Success(); + } } }