当前位置:网站首页>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
边栏推荐
- 1-4 configuration executable script of nodejs installation
- Bottom processing of stack memory in browser
- 手写事件发布订阅框架
- Decimal format decimal / datetime conversion processing
- Promise (I)
- Collect blog posts
- Freecodecamp ---- budget & category exercise
- Aiot industrial technology panoramic structure - Digital Architecture Design (8)
- 如何用Redis实现分布式锁?
- Lock lock
猜你喜欢
Quick install mongodb
SQL database
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
Further study of data visualization
org. apache. parquet. schema. InvalidSchemaException: A group type can not be empty. Parquet does not su
【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明
feign报400处理
Document operation II (5000 word summary)
线性代数感悟之2
Understanding of RPC core concepts
随机推荐
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
1-2 JSX syntax rules
STM32__ 03 - beginner timer
文件操作《二》(5000字总结篇)
C# Task. Delay and thread The difference between sleep
Production environment——
Get the column name list of the table quickly in Oracle
How does matlab draw the curve of known formula and how does excel draw the function curve image?
matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
MySQL modify master database
1-2 characteristics of nodejs
Zhimeng dedecms security setup Guide
An essay on the classical "tear down the wall in thinking"
RPC核心概念理解
Sub database and sub table & shardingsphere
Clickhouse SQL operation
Shell脚本——Shell编程规范及变量
Smart doc + Torna generate interface document
JSON deserialize anonymous array / object
Scope and scope chain in JS