Hi there,
I looked at the implementation of Job.LastSuccessfulRun and found this code (decompiled):
    public DateTime? LastSuccessfulRun
    {
      get
      {
        if (Job._logFiles.Value.Any<FileInfo>())
        {
          Regex dataIntegrationLogFilePattern = new Regex(Regex.Escape(Task.MakeSafeFileName(this.Name)) + "\\d{4}\\d{2}\\d{2}-\\d{2}\\d{2}\\d{2}\\d+.log");
          foreach (FileInfo fileInfo in (IEnumerable<FileInfo>) Job._logFiles.Value.Where<FileInfo>((Func<FileInfo, bool>) (file => dataIntegrationLogFilePattern.IsMatch(file.Name))).OrderByDescending<FileInfo, DateTime>((Func<FileInfo, DateTime>) (obj => obj.CreationTime)))
          {
            if (File.ReadLines(fileInfo.FullName).Last<string>().EndsWith("Batch succeeded.", StringComparison.OrdinalIgnoreCase))
              return new DateTime?(fileInfo.CreationTime);
          }
        }
        return new DateTime?();
      }
    }
This code loops through all the log files and finds the newest file that ends with "Batch succeeded". I can see these log files when I run the job manually. However, when run from a scheduled task, the log fille is different from what I can see. I ends like this:
2022-03-15 06:06:46.415: Update products information finished.
2022-03-15 06:06:51.075: Job succeeded.
whereas the one from running the job directly looks like this:
2022-02-19 10:05:59.206: Update products information finished.
2022-02-19 10:06:06.659: Job succeeded.
2022-02-19 10:13:00.917: Finished job - 0. Import from NAV - EcomProvider.
2022-02-19 10:13:00.933: Batch succeeded.
Is that a correct analysis? And if so, would it mean that LastSuccessfulRun is unreliable as it means "last manual run" as opposed to "last run from anywhere including a scheduled task"?
I am trying to find out when the job last ran in order to optimize the import.
Thanks,
Imar
 
                                             
                                         
                                                     
                             
                                                     
                        							 
                                                     
                                                     
                             
                             
                             
                    