当前位置:网站首页>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
边栏推荐
- Decimal format decimal / datetime conversion processing
- Bottom processing of stack memory in browser
- [registration] tf54: engineer growth map and excellent R & D organization building
- [pimf] openharmony paper Club - what is the experience of wandering in ACM survey
- 手写事件发布订阅框架
- AIOT产业技术全景结构-数字化架构设计(8)
- Tencent resolves the address according to the IP address
- Milvus 2.0 質量保障系統詳解
- Understanding of RPC core concepts
- Signalr can actively send data from the server to the client
猜你喜欢

【生活中的逻辑谬误】稻草人谬误和无力反驳不算证明

Milvus 2.0 质量保障系统详解

Signalr can actively send data from the server to the client

JS, entries(), keys(), values(), some(), object Assign() traversal array usage

Smart doc + Torna generate interface document

【WPF绑定3】 ListView基础绑定和数据模板绑定

Devexpress GridView add select all columns

网络安全之渗透靶场实战详解

Go language, array, string, slice

Clickhouse table engine
随机推荐
Preliminary understanding of promse
如何用Redis实现分布式锁?
MySQL restores data through binlog file
Shell-入门、变量、以及基本的语法
VLAN高级技术,VLAN聚合,超级Super VLAN ,Sub VLAN
Freecodecamp ---- budget & category exercise
freeCodeCamp----prob_ Calculator exercise
[PROJECT] small hat takeout (8)
ASP. Net core reads the configuration file in the class library project
Talk about browser cache control
【WPF绑定3】 ListView基础绑定和数据模板绑定
Calculation formula related to tolerance analysis
[pimf] openharmony paper Club - what is the experience of wandering in ACM survey
freeCodeCamp----shape_ Calculator exercise
Understanding of RPC core concepts
On lambda powertools typescript
. net cross platform principle (Part I)
【解决报错】Error in v-on handler: “TypeError: Cannot read property ‘resetFields’ of undefined”
Kingdee Cloud Star API calling practice
Use of shell sed command