Episerver Scheduled jobs - Give feedback!
- Part 1: Make it fail!
- Part 2: Give feedback!
- Part 3: Stop and restart!
- Part 4: Add a GUID!
Have you ever wondered what your long-running scheduled job is doing right now? Are you waiting for it to finish, and considering if you have time for a coffee?
Make your jobs give feedback!
It's as easy as calling OnStatusChanged in ScheduledJobBase. Quick code example:
[ScheduledPlugIn(DisplayName = "My scheduled job")]
public class MyScheduledJob : ScheduledJobBase
{
public override string Execute()
{
for (var i = 0; i < Items.Count(); i++)
{
FinishItem(Items[i]);
OnStatusChanged(i + " items finished.");
}
return Items.Count() + " items finished successfully.";
}
}
While running the job, it will look like this:

Warning! As every call to OnStatusChanged triggers a database write, where the current status message is written to the column CurrentStatusMessage for the jobs row in the table tblScheduledItem, you should be careful calling OnStatusChanged inside a loop like in my example above.
Call OnStatusChanged outside loops, or add a condition like if (i % 10000 == 0) OnStatusChanged(i);.
That's it!