Scheduled Tasks Not Running (Moodle 3.8.1)

Scheduled Tasks Not Running (Moodle 3.8.1)

by Sergio Guerrero -
Number of replies: 5

Hello,

This is for Moodle 3.8.1.

I cannot get the scheduled tasks to run. The 'Next Run' column always shows as ASAP. The only way to get tasks to run is by doing them manually (Run Now option).

We have Moodle Cron installed in our app server and is always running.


Have set the correct path to our PHP CLI.


Not sure what it is that I may be missing. Any help is greatly appreciated. 


Thanks,

Sergio


Average of ratings: -
In reply to Sergio Guerrero

Re: Scheduled Tasks Not Running (Moodle 3.8.1)

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
There may or may not be a connection. The 3.8 series made it to PHP 7.4 only with the 3.8.4 release.
In reply to Sergio Guerrero

Re: Scheduled Tasks Not Running (Moodle 3.8.1)

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

That Moodle Cron package installs as a service, the service process runs continually running the cron as scheduled in its configuration.

But it runs the cron using the web interface to the cron script and this is blocked by default. You need to disable Cron execution via command line only (under Site administrationSecuritySite security settings) to use the above.

Instead of using the above package I've always found that using the standard Task Scheduler in Windows works well. Set it up to run php-win.exe, provide the full path to admin\cli\cron.php as the parameter and run it as account SYSTEM.

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Scheduled Tasks Not Running (Moodle 3.8.1)

by Sergio Guerrero -
Thank you for your reply Leon. I have created a task in the Windows Task Scheduler, but get the following message , "The operator or administrator has refused the request. (0x800710E0)."
The task keep running for ever and never completes. I have the task set to run as SYSTEM with elevated privileges and made sure the SYSTEM account does have permissions to run the php-win.exe and cron.php scripts. Not sure what could cause this issue.

I looked at PHP support documentation based on Visvanath's advice.
MDL-63420 - PHP 7.3 can be used with Moodle 3.6.4, Moodle 3.7 and later releases.
MDL-66260 - PHP 7.4 can be used with Moodle 3.8.3, Moodle 3.9 and later releases.

And tried using PHP 7.3 instead, but get the same results. Our Moodle is currently being hosted in a Windows 2019 server (Moodle v3.8.1).

Oddly enough, this solution works perfectly in our test environment. Our test environment is a Windows 2012 server with PHP 7.2 and Moodle v3.8+.
Not sure what to try next. Any suggestions are welcomed.
 
In reply to Sergio Guerrero

Re: Scheduled Tasks Not Running (Moodle 3.8.1)

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The first thing I try when troubleshooting the scheduled task is to try it at the command prompt. For my site I run the command prompt as administrator and try:

C:\>"C:\Program Files\PHP\7.2.32\php.exe" C:\Inetpub\test_site\moodle\admin\cli\cron.php

If this works with no errors then I set up the scheduled task. The steps you describe sound correct but here are the settings from my Windows Server 2016 system:

Scheduled task: create task

Run as NT AUTHORITY\SYSTEM, select Run with highest privileges.

Scheduled task: new action

Use php.exe at the command line but use php-win.exe here because there'll be nowhere to send the output.

Scheduled task: new trigger

If it's working correctly you should see the last run result of 0x0:

Last Run Result (0x0)

I've never encountered that 0x800710E0 error. If it's working for you on Windows Server 2012 and for me on 2016, maybe it's a Windows Server 2019 issue but I've no evidence for that. Maybe running the command via a batch file will help troubleshoot this (you can run php.exe and redirect the output to a log file).

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Scheduled Tasks Not Running (Moodle 3.8.1)

by Sergio Guerrero -

I just managed to get the Moodle Cron process to run successfully this morning! The culprit was the scheduled task named, Predict Models; it was always hanging and preventing the process to continue.

I found this out after running the command like you suggested. I can't believe I overlooked this.

As far as the set up for the Task Scheduler, I had everything almost exactly like yours. I have decided to disable the Predict Models task from running and so far no issues have been experienced.

Thank you very much for your help!

Average of ratings: Useful (1)