DiluzFerz
DiluzFerz

Reputation: 53

How to keep a schedule alive (created using Quartz & .Net Core) - as it is not working after some time after deployed on IIS

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

Upvotes: 0

Views: 1768

Answers (2)

DiluzFerz
DiluzFerz

Reputation: 53

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.

Upvotes: 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)
        {
            .....

Upvotes: 0

Related Questions