Try our conversational search powered by Generative AI!

Restartable Job not restarting

Vote:
 

Having taken some advice from a previous forum post, I'm using 'Debugger.Launch' like so...

public override string Execute()
{
    Debugger.Launch();

..to attach to my scheduled job whenever it is run. I presume I'm using the correct attribute to create a restartable scheduled job...

[ScheduledPlugIn(DisplayName = "MyScheduledJob",Restartable = true)]
public class MyScheduledJob : ScheduledJobBase

but my job isn't restarting when I...

a. ...kill the IIS Worker Process

b. ...recycle the app pool

c. ...set the app pool idle timeout to 2 minutes

If I then call my job directly, its happy to start work and pick up from where it left off, so it appears it's just episerver not asking for it to start again after it stops

How do I simulate a correct restartable situation?

#217631
Feb 26, 2020 14:17
Vote:
 

From the documentation

"When the application restarts, the jobs that are marked as restartable will be executed immediately if the <see cref="ScheduledJob.LastExecutionAttempt"/> has not exceeded the <see cref="Scheduler.SchedulerOptions.MaximumExecutionAttempts"/>."

Probably that's something you should look into? 

MaximumExecutionAttempts is default to 10, and LastExecutionAttempt should be saved to database - look into tblScheduledItem and you should see it 

#217632
Feb 26, 2020 14:47
Vote:
 

Quan that looks like a quote but no search engine is show me where that text is, and the documentation page I've got doesn't mention those values either..

https://world.episerver.com/documentation/developer-guides/CMS/scheduled-jobs/

have you got a direct link for me please to that documentation?

#217633
Feb 26, 2020 14:54
Vote:
 

Thanks Quan,

Ok, so if ScheduledJob.LastExecutionAttempt is an integer count, and Scheduler.SchedulerOptions.MaximumExecutionAttempts is the upper limit allowed....

how do I set those values? ScheduledPlugInAttribute does not allow them to be set and my job extends ScheduledJobBase which doesn't allow them to be set either. Feel like I'm being a bit thick and missing something obvious here

#217635
Feb 26, 2020 15:08
Vote:
 

I'm not entirely sure, but you might be able to do this

ServiceLocator.Current.GetInstance<SchedulerOptions>().MaximumExecutionAttempts = 100;

LastExecutionAttempt should be reset to 0 after the job is successfully completed

#217636
Feb 26, 2020 15:17
Vote:
 

I've noticed the admin panel for my job now has a 'stop' button after a restart...

but my scheduled job still hasn't run, and i know this because the 'Debugger.Launch()' code in my Execute() method isn't getting hit.

So it kinda thinks it should be running but I see no evidence of it running

#217642
Feb 26, 2020 15:51
Vote:
 

Hi Noel,

Have you implemented a way to actually stop the job and reset things ready for another run? In the back of my mind I'm sure I remember reading that a job must be stoppable in order to also be restartable... could be wrong though, and maybe you already do this?

#217727
Feb 28, 2020 8:52
Vote:
 

Hi James,

Actually I think thats why the "stop job" button appearred that i screenshot'ed above. At first i was hoping it meant it was running, but now i think it's because episerver knows the job is now stoppable. Yeah I've written everything to allow insert or update, and then i store my progress in the DDS, and have a job editors can use to restart the job is anything goes wrong. 

I think the problem was in my logic somewhere, initially was hoping someone would tell me my setup was wrong, but just my logic instead :-( lol

#217728
Feb 28, 2020 10:23
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.