-1

I have a list of jobs and they have their data. Also, I have an API to change their data source (LastParsedBlock) and I want it to stop that specific job when I change the data and start all the processes from the beginning and I don't want it to wait for it to complete.

[HttpPut("LastParsedBlock")]
        public async Task<ActionResult> ChangeLastParsedBlockAsync([FromBody] ChangeLastParsedBlockDto dto)
        {
            var jobkey = new JobKey(dto.CoinId.ToString());

            var scheduler = await _schedulerFactory.GetScheduler();
            var jobDetail = await scheduler.GetJobDetail(jobkey);

            if (jobDetail != null)
                await scheduler.PauseJob(jobkey);

            var handler = Handlers.SingleOrDefault(x => x.Id == dto.CoinId); 
            handler.LastParsedBlock = dto.NewLastParsedBlock;        //changing data source


            await scheduler.ResumeJob(jobkey); //it doesn't restart, just resumes

            return Ok($"Changed successfuly.");
        }

1 Answers1

0

I think you need to use the scheduler.rescheduleJob() method to restart the job. This method takes two parameters, the job key and the new trigger. The new trigger can be a copy of the old trigger, or it can be a new trigger with different settings.

var jobKey = new JobKey(dto.CoinId.ToString());
var newTrigger = TriggerBuilder.Create()
    .WithSchedule(SimpleScheduleBuilder.RepeatMinutelyForever())
    .Build();

scheduler.rescheduleJob(jobKey, newTrigger);

This code will reschedule the job to run every minute, starting immediately.

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197