3

I have a very basic question and only because I haven't been able to find any reference or source for it.

In Sitecore, how can I programmatically get the last run date/time of a job that is configured in the web.config or another config file? I had opened another question like this 2-3 years ago but the suggestions there don't really provide any help.

Any help or guidance is appreciated!

  • Thanks Marek but I'm looking for a programmatical way of getting these times and I've updated my question. I'm looking to get date time fo the publish job if it makes sense. – Gabbar Nov 27 '16 at 21:24
  • As I understand your question, you are currently using an <agent>. Would you consider creating a Sitecore scheduled task? Then you could see the last run time on the schedule item: i.imgur.com/rtWIDkp.png – Dmytro Shevchenko Nov 27 '16 at 21:49
  • The publish task last run date time is what I want to capture. Since this is already OOTB, I don't feel like recreating it. – Gabbar Nov 27 '16 at 21:50
  • @Gabbar in that case, you can use Database.Properties.GetLastPublishDate(Database target, Language language) – Dmytro Shevchenko Nov 27 '16 at 21:52
4

You cannot.

When Sitecore executes any job, it runs <job> pipeline defined in Sitecore.config (or web.config in older versions). This pipeline has SignalStart and SignalEnd processors, but the only thing they do is logging the information that job started or finished:

public static void SignalStart(JobArgs args)
{
  Job job = args.Job;
  job.Status.LogInfo("Job started: {0}", job.Name);
}

public static void SignalEnd(JobArgs args)
{
  Job job = args.Job;
  string str = string.Empty;
  if (job.Status.Processed > 0L)
    str = job.Status.Processed.ToString();
  job.Status.LogInfo("Job ended: {0} (units processed: {1})", job.Name, str);
}

You can do what you need manually by analyzing the log files (see https://sitecore.stackexchange.com/a/1234/277 ) or you can add your own custom processors to the pipeline mentioned above and store this information in some other place / database / whatever suits you best.

| improve this answer | |
  • Marek .. thanks for the input but Dmytro's property is what I was looking for. – Gabbar Nov 29 '16 at 15:48

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.