Search code examples
c#.netschedulerquartz

Quartz Scheduler block inactive user job


I am currently working with Quartz Scheduler and I am trying to make a feature, which will be blocking an user if he is inactive for example for more than two days, but unfortunately I didn't work with Quartz Scheduler and I have no idea how to do that.


Solution

  • Well then, you will have a daily cron or an hourly cron (depending on the sensitivity) that checks that value and update the user.

    public class CheckForInactiveUsers: IJob
    {
        public async Task Execute(IJobExecutionContext context)
        {
            // here you do your business
        }
    }
    
    
    IJobDetail job = JobBuilder.Create<CheckForInactiveUsers>()
        .WithIdentity("checkForInactiveUsers", "group1")
        .Build();
    
    ITrigger trigger = TriggerBuilder.Create()
        .WithIdentity("trigger1", "group1")
        .StartNow()
        .WithSimpleSchedule(x => x
            .WithIntervalInHours(1)
            .RepeatForever())
        .Build();
    
    await scheduler.ScheduleJob(job, trigger);