Quantcast
Channel: briancaos – Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 276

Sitecore The type or namespace name ‘Job’ does not exist in the namespace ‘Sitecore.Jobs’ (are you missing an assembly reference?)

$
0
0

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:


Viewing all articles
Browse latest Browse all 276

Trending Articles