2

We have this feature which is responsible for starting Sitecore Index Refresh jobs programmatically using the static class Sitecore.Jobs.JobManager (for different crawler roots).

Now I'd like to create a method to fetch which is the current state of a given job.

Do you guys and gals know how that could be done?

4

Finally figured out how to do this.

Firstly, you want to make sure you start the Refresh/Rebuild properly.

What I mean by that is that if you want to be able to identify the right crawler related to a given Indexing Job, you will need to tag the Indexing Job with some ID.

You can do that by adding a Message to the job when starting it.

Job myRefreshJob = IndexCustodian.Refresh(p_Index, p_PathItem);
myRefreshJob.Status.Messages.Add("Index Refresh IndexName={YOUR_INDEX_NAME} Path={THE_CRAWLER_ROOT_PATH}");

By doing that, you will be able to easily identify the given job among all the jobs returned by the JobManager.

Job foundJob = JobManager.GetJobs().FirstOrDefault(currentJob => currentJob.Status.Messages.Contains("THE_CRAWLER_ROOT_PATH"));
JobState jobState = foundJob.Status.State;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.