0

I have created a scheduler API using Quartz & .Net Core. How to keep this schedule alive, as it is not working after some time?

It's possible to handle this in Application_Start() according to this link: Can you prevent your ASP.NET application from shutting down?.

Or is this possible to do in a .Net Core scheduler, in Startup.cs? Or where can I use this kind of request creation to keep the schedule alive? Appreciate any help. Thanks

EDIT: I created a Windows PowerShell script to create requests for the scheduler to keep the scheduler alive. It solved the issue. (Codes are included in my answer below). Thanks

DiluzFerz
  • 53
  • 2
  • 11

2 Answers2

0

I usually schedule quartz jobs in the Startup.cs of a .Net.Core App, and the job is alive forever.

In public void ConfigureServices(IServiceCollection services) register factory and scheduler :

services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
IScheduler scheduler = services.BuildServiceProvider().GetService<ISchedulerFactory>().GetScheduler().Result;
services.AddSingleton<IScheduler>(scheduler);

In public async void Configure(IApplicationBuilder app..... schedule the jobs

serviceProvider.GetService<IScheduler>().Start();
Quartz.IScheduler _scheduler = serviceProvider.GetService<Quartz.IScheduler>();
//Define job
IJobDetail job = JobBuilder.CreateForAsync<IJobImplementationXXXXX>()
    .WithIdentity("job_namexxxx")
    .Build();
//Define trigger
ITrigger trigger = TriggerBuilder.Create()
    .WithIdentity("trigger_namexxxx")
    .StartNow()
    .WithSimpleSchedule(x => x
          .WithInterval(TimeSpan.FromMilliseconds(PollingIntervalxxxx))
          .RepeatForever())
    .Build();
//Execute Job
await _scheduler.ScheduleJob(job, trigger);

And of course the IJob implementation that will be exec every PollingInterval

[DisallowConcurrentExecution]
public class IJobImplementationXXXXX: IJob
{
     public async Task Execute(IJobExecutionContext context)
        {
            .....
  • Thank you Raul. My scheduled job also with similar codes (with .RepeatForever() in specific time interval). Issue is, after deployed on IIS, after few hours, job doesn't execute. Identified it by reading logs. After some hours, no log messages are there. I followed this article related to Quartz with .Net Core: https://byteloom.marek-mierzwa.com/2017/04/13/scheduling-in-asp-net-core-with-quartz-net.html – DiluzFerz Oct 09 '18 at 08:22
  • I followed this article: https://byteloom.marek-mierzwa.com/2017/04/13/scheduling-in-asp-net-core-with-quartz-net.html – DiluzFerz Oct 09 '18 at 08:24
  • I created a powershell script to create requests for the scheduler to keep the scheduler alive. It solved the issue. Thanks (Therefore I have edited the above question) – DiluzFerz Oct 16 '18 at 05:32
0

I created a powershell script to create requests for the scheduler to keep the scheduler alive. It solved the issue. (Therefore I have edited the above question with this answer)

Script:

$url = "http://localhost/someAtion"
Invoke-WebRequest -Uri $url

Created a windows task scheduler to execute this script in specific intervals.

DiluzFerz
  • 53
  • 2
  • 11