Quartz.Net에서 매우 자주 트리거되는 작업을 수행하고 때로는 오래 실행되는 경우 작업이 이미 실행중인 경우 트리거를 어떻게 취소합니까?Quartz.Net의 장기 실행 작업
답변
더 일반적인 방법은 IInterruptableJob을 사용하는 것입니다 (http://quartznet.sourceforge.net/faq.html#howtostopjob 참조). 물론 이것은 (! jobRunning) if (! jobRunning)를 말하는 또 다른 방법입니다.
작업이 시작될 때 일종의 전역 변수 (jobRunning = true)를 설정하지 않고 작업이 완료되면 다시 되돌릴 수 있습니까? (거짓 jobRunning ==)
예, 종종 가장 간단한 해결책이 가장 좋습니다. 나는 이것을 구현했는데, 첫 번째 작업이 완료 될 때까지 작업을 일시 중지 한 구현 된 솔루션이 있지만,이 작업은 정상적으로 작동합니다! –
앱 시작시 작업 목록에서 자신을 제거하고 종료 자체를 삽입 할 수있는 경우
그런 다음 트리거 화재, 당신의 코드를 실행하면.
요즘에는 "WithMisfireHandlingInstructionIgnoreMisfires"를 트리거에 사용하고 작업에서 [DisallowConcurrentExecution] 특성을 사용할 수 있습니다.
이것은 구현 한 것입니다 (MarkoL이 이전에 준 링크에서 제안 사항을 사용함).
나는 타이핑을 좀 저장하려고합니다.
저는 Quartz.NET에서 꽤 새로워졌습니다. 그래서 아래에서 소금 기차를 가져 가세요.
public class AnInterruptableJob : IJob, IInterruptableJob
{
private bool _isInterrupted = false;
private int MAXIMUM_JOB_RUN_SECONDS = 10;
/// <summary>
/// Called by the <see cref="IScheduler" /> when a
/// <see cref="ITrigger" /> fires that is associated with
/// the <see cref="IJob" />.
/// </summary>
public virtual void Execute(IJobExecutionContext context)
{
/* See http://aziegler71.wordpress.com/2012/04/25/quartz-net-example/ */
JobKey key = context.JobDetail.Key;
JobDataMap dataMap = context.JobDetail.JobDataMap;
int timeOutSeconds = dataMap.GetInt("TimeOutSeconds");
if (timeOutSeconds <= 0)
{
timeOutSeconds = MAXIMUM_JOB_RUN_SECONDS;
}
Timer t = new Timer(TimerCallback, context, timeOutSeconds * 1000, 0);
Console.WriteLine(string.Format("AnInterruptableJob Start : JobKey='{0}', timeOutSeconds='{1}' at '{2}'", key, timeOutSeconds, DateTime.Now.ToLongTimeString()));
try
{
Thread.Sleep(TimeSpan.FromSeconds(7));
}
catch (ThreadInterruptedException)
{
}
if (_isInterrupted)
{
Console.WriteLine("Interrupted. Leaving Excecute Method.");
return;
}
Console.WriteLine(string.Format("End AnInterruptableJob (should not see this) : JobKey='{0}', timeOutSeconds='{1}' at '{2}'", key, timeOutSeconds, DateTime.Now.ToLongTimeString()));
}
private void TimerCallback(Object o)
{
IJobExecutionContext context = o as IJobExecutionContext;
if (null != context)
{
context.Scheduler.Interrupt(context.FireInstanceId);
}
}
public void Interrupt()
{
_isInterrupted = true;
Console.WriteLine(string.Format("AnInterruptableJob.Interrupt called at '{0}'", DateTime.Now.ToLongTimeString()));
}
}
- 1. Quartz.net의 작업 실행 시간
- 2. 레일에서 장기 실행 작업
- 3. 프레임 워크 장기 실행 작업
- 4. asp.net ThreadPool - 장기 실행 작업
- 5. PLINQ에서 장기 실행 작업 취소
- 6. TPL에서 장기 실행 작업 중단
- 7. 장기 실행 작업 성능 팁
- 8. 시트 및 장기 실행 작업
- 9. SQL Server에서 장기 실행 작업 실행
- 10. .NET : 장기 실행 작업 동기화를위한 메커니즘
- 11. ASP.NET MVC 및 장기 실행 작업
- 12. 장기 실행 유닛 테스트에서 취소 조정 작업
- 13. 스윙, 수동보기 및 장기 실행 작업
- 14. appwidget을 업데이트하기위한 안드로이드 장기 실행 작업
- 15. 장기 실행 병합
- 16. 장기 실행 프로세스 종료
- 17. 장기 실행 프로세스는
- 18. VB.NET에서 장기 실행 작업 중에 진행률 막대를 강제로 업데이트하려면 어떻게해야합니까?
- 19. PHP CLI 또는 아파치 (PHP를 통한 장기 실행 작업)
- 20. WSS 기능에서 장기 실행 작업 호출 OnActivated 이벤트
- 21. SwingWorker 스레드에서 실행되는 "장기 실행 작업"의 자격은 무엇입니까?
- 22. MOSS 게시 인프라를 사용하여 장기 실행 작업 지원
- 23. ASP.NET 다중 스레드 및 장기 실행 작업 시간 초과
- 24. 장기 실행 비동기 프로세스의 Main() 메서드와 가장 잘 맞는 작업
- 25. Quartz.NET의 클로즈드 소스 대안
- 26. 파일을 반환하는 장기 실행 프로세스
- 27. 장기 실행 파이썬 스레드 종료
- 28. IIS에서 장기 실행 프로세스 호스팅
- 29. 장기 실행 웹 서비스 아키텍처
- 30. 장기 실행 프로세스에 JMS 사용?
은 한 번에 허용 된 IInterruptableJob을 구현하는 해당 클래스의 하나의 인스턴스이거나 해당 클래스를 사용하는 작업입니까? –
한 번에 하나의 인스턴스 만 허용하려는 경우 IStatefulJob은 프라이드 한 http://quartznet.sourceforge.net/faq.html#howtopreventconcurrentfire입니다. IInterruptableJob은 인터럽트 신호를 보내는 표준 방법을 제공하며 작업 측면에서 무거워 할 필요가 있습니다 (중단 플래그가 발생했는지 확인). –