From Sitecore 9.0 to Sitecore 9.2, Sitecore updated the Jobs namespace:
- Job have become Sitecore.Abstractions.BaseJob abstract class and Sitecore.Jobs.DefaultJob concrete implementation.
- JobOptions have become Sitecore.Abstractions.BaseJobOptions abstract class and Sitecore.Jobs.DefaultJobOptions.
This resonates with the Sitecore structural changes where Sitecore implements abstractions for most of their code. This change began all the way back in Sitecore 7.5 and makes it possible for the Sitecore development team to perform unit tests.
So you’ll need to change your Jobs code:
GET ALL JOBS:
public IEnumerable<Sitecore.Abstractions.BaseJob> Jobs
{
get
{
return Sitecore.Jobs.JobManager.GetJobs().OrderBy(job => job.QueueTime);
}
}
GET STATUS OF A JOB:
protected string GetJobMessages(Sitecore.Jobs.DefaultJob job)
{
System.Text.StringBuilder sb = new StringBuilder();
if (job.Options.ContextUser != null)
sb.AppendLine("Context User: " + job.Options.ContextUser.Name);
sb.AppendLine("Priority: " + job.Options.Priority.ToString());
sb.AppendLine("Messages:");
foreach (string s in job.Status.Messages)
sb.AppendLine(s);
return sb.ToString();
}
CREATE A NEW JOB:
string jobName = "MyJob"
DefaultJobOptions options = new DefaultJobOptions(jobName, "Update", Sitecore.Context.Site.Name, this, "Update", new object[] { }) { ContextUser = Sitecore.Context.User, Priority = System.Threading.ThreadPriority.Normal };
JobManager.Start(options);
UPDATE STATUS OF JOB:
Sitecore.Abstractions.BaseJob job = JobManager.GetJob(jobName);
job.Status.State = JobState.Running;
job.Status.Total = 42;
MORE TO READ:
- The type or namespace name ‘Job’ could not be found (are you missing a using directive or an assembly reference?) from Stackexchange
- What is Sitecore.Abstractions dll? from Stackexchange
- Using Sitecore Jobs from briancaos
- Sitecore remove “Job started” and “Job ended” from log files from briancaos
- Sitecore Job Viewer – see what Sitecore is doing in the background from briancaos
- Case Study – Upgrading Sitecore 9.0.1 to 9.3 on an enterprise site by Matt Fletcher