I recently tried to switch to launched on my Mac Mini (10.7.5) from cron on a PC. I searched and think I have things set up right, but it seems that the scheduled script starts significantly after the requested time. Details at https://stackoverflow.com/questions/32829026/using-launched-and-plist-starts-late. Thanks for guidance or experiments to try.
Since your per-user launch agent does actually execute, albeit later than scheduled, it is highly likely that your system may be asleep at the scheduled time. I would recommend reading through the man page by running the following command from a terminal session:
$ man 5 launchd.plist
StartInterval option specifically, the man page has this to say:
Unlike cron which skips job invocations when the computer is asleep, launchd will start the job the next time the computer wakes up. If multiple intervals transpire before the computer is woken, those events will be coalesced into one event upon wake from sleep.
If you are working remotely, or not physically present at the scheduled time — which is not clear from your question — a good starting point would be to confirm that the system has not entered sleep mode prior to the scheduled time of your launch agent.
Note that the documentation for
StartInterval has changed as of 10.10, see https://forums.developer.apple.com/thread/23361 for a thread documenting this change.
The new text reads
This optional key causes the job to be started every N seconds. If the system is asleep during the time of the next scheduled interval firing, that interval will be missed due to shortcomings in kqueue(3). If the job is running during an interval firing, that interval firing will likewise be missed.
Apparently this has always been 'broken' and the documentation has been updated to reflect that.
So the answer is that
StartInterval doesn't handle sleep, and you can either prevent sleep (as you found) or switch to another method to trigger your job. For instance
StartCalendarInterval does coalesce events after returning from sleep, so that might be a good option.
OK, I turned off "sleep"ing and the scheduled job starts and ends as expected. My next step is to run with the full 2 hour job run time. I had experimented with the jobs runnings 2 minutes each as a test, and they did. So next step is the real job, but I expect it to work. I'll report when it does. Thanks for the suggestion/solution.
OK, that was it. It was "sleep"ing whenever a job was to start. Not letting it sleep now allows all jobs to run as expected. Thanks.