当前位置:网站首页>Using quartz under. Net core - calendar of [6] jobs and triggers
Using quartz under. Net core - calendar of [6] jobs and triggers
2022-04-23 17:10:00 【Tomato Warrior】
Trigger calendar allows you to block the execution of jobs within a certain period of time
Complete code :
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
// Register scheduler factory
services.AddSingleton<ISchedulerFactory>(new StdSchedulerFactory());
}
HomeController.cs
using Microsoft.AspNetCore.Mvc;
using Quartz;
using Quartz.Impl.Calendar;
using System;
using System.Threading.Tasks;
namespace QuartzLearn.Controllers
{
public class HomeController : Controller
{
// Dispatcher factory
private readonly ISchedulerFactory _schedulerFactory;
// Constructor injection
public HomeController(ISchedulerFactory schedulerFactory)
{
// Injection scheduler factory
_schedulerFactory = schedulerFactory;
}
public async Task<IActionResult> Index()
{
IScheduler scheduler = await _schedulerFactory.GetScheduler();
await scheduler.Start();
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "jobGroup1")
.UsingJobData("name", "zhangsan")
.Build();
// Calendar instance
HolidayCalendar cal = new HolidayCalendar();
// Date of shielding
cal.AddExcludedDate(DateTime.Parse("2020-11-12"));
await scheduler.AddCalendar("myHolidays", cal, false,false);
// Every day 9:30 Trigger once per minute
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(9, 30))
.ModifiedByCalendar("myHolidays") // be not in myHolidays Date triggers
.Build();
await scheduler.ScheduleJob(job, trigger);
return View();
}
}
[DisallowConcurrentExecution]
[PersistJobDataAfterExecution]
public class HelloJob : IJob
{
public string Name { private get; set; }
public async Task Execute(IJobExecutionContext context)
{
await Console.Out.WriteLineAsync($"This is HelloJob {DateTime.Now}");
}
}
}
版权声明
本文为[Tomato Warrior]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230553457733.html
边栏推荐
- Go language, array, string, slice
- New keyword learning and summary
- groutine
- Clickhouse - data type
- C# Task. Delay and thread The difference between sleep
- El date picker limits the selection range from the current time to two months ago
- Idea of batch manufacturing test data, with source code
- Use between nodejs modules
- Promise (IV)
- Feign report 400 processing
猜你喜欢
Detailed explanation of Niuke - Gloves
Milvus 2.0 détails du système d'assurance de la qualité
基于51单片机红外无线通讯仿真
Sub database and sub table & shardingsphere
On lambda powertools typescript
How vscode compares the similarities and differences between two files
CentOS MySQL multi instance deployment
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
. net type transfer
Detailed explanation of the penetration of network security in the shooting range
随机推荐
Sub database and sub table & shardingsphere
Variable length parameter__ VA_ ARGS__ Macro definitions for and logging
Document operation II (5000 word summary)
Shortcut keys (multiline)
RTKLIB 2.4.3源码笔记
Detailed explanation of C webpai route
Tencent resolves the address according to the IP address
New keyword learning and summary
Preliminary understanding of promse
On lambda powertools typescript
Use between nodejs modules
1-2 characteristics of nodejs
Quick install mongodb
El date picker limits the selection range from the current time to two months ago
Generate random numbers with high quality and Gaussian distribution
MySQL master-slave configuration under CentOS
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
About stream flow, write it down briefly------
Shell-入门、变量、以及基本的语法
Solution architect's small bag - 5 types of architecture diagrams