Ad hoc tasks not running / fails in task logs

Ad hoc tasks not running / fails in task logs

by Aaron Stockdale -
Number of replies: 9
My ad hoc task queue has been filling up.  When I run cron manually via the web all tasks complete.

My system status says that cron is running and that no tasks are failing, but when I check the task log it shows that every task fails until I run cron manually again, after which it shows a bunch of successes.

System status

The task log currently shows Cleanup old sessions, Grade Me, Free up memory used by expired entries in Redis caches, Cleanup contexts, and Cleanup task for recent activity block failing over and over. 

mdl_task_adhoc shows 5 tasks in queue, all of which are send_login_notifications

If I run cron manually, all the ad_hoc tasks and the tasks failing in the logs will complete successfully.

Average of ratings: -
In reply to Aaron Stockdale

Re: Ad hoc tasks not running / fails in task logs

by Jason Hollowell -
Picture of Particularly helpful Moodlers
Aaron,

I just ran across your post after trying, to no avail, to figure out why my instance of Moodle stopped sending e-mail after upgrading to 4.3. I am on Apache, upgraded PHP to 8.0, and confirmed that e-mail is sent via the "Test Outgoing E-Mail Configuration" feature. I had e-mail before the upgrade (which note, did include a PHP upgrade) and now I don't. I guess my problem is not PHP because the browser-based "Test outgoing configuration" works fine.

After seeing your post, I see that all of my tasks have been failing since I upgraded to 4.3. Hmm, I'm perplexed...

Hopefully someone has an idea here. My issue is that manually running the cron doesn't do anything. I get a message saying:

"Ran 0 adhoc tasks found at Date, Time..
Cron run completely correctly"

Clearly something is failing but I'm getting no message to help me figure out what and where sad
Average of ratings: Useful (1)
In reply to Jason Hollowell

Re: Ad hoc tasks not running / fails in task logs

by Jason Hollowell -
Picture of Particularly helpful Moodlers
Replying to myself here with some additional information. I turned on the cron output, ran it manually and watched it repeat the same line over and over for 180 seconds. The final line looks like this:

Adhoc task custom data: {"ismoodleapp":false,"useragent":"Mozilla\/5.0 (iPhone; CPU iPhone OS 17_3 like Mac OS X) AppleWebKit\/605.1.15 (KHTML, like Gecko) CriOS\/122.0.6261.62 Mobile\/15E148 Safari\/604.1","loginip":"49.109.102.44","logintime":1710394851}
!!! Coding error detected, it must be fixed by a programmer: A lock was created but not released at:
[dirroot]/lib/classes/cron.php on line 256

Code should look like:

$factory = \core\lock\lock_config::get_lock_factory('type');
$lock = $factory->get_lock(247b38462a218aaf80fe824262c0c6ed380aae21);
$lock->release(); // Locks must ALWAYS be released like this.

I have no idea if that could be connected to my issue but it looks like something that requires attention...?
Average of ratings: Useful (1)
In reply to Jason Hollowell

Re: Ad hoc tasks not running / fails in task logs

by Ken Task -
Picture of Particularly helpful Moodlers
Would help to know what version of Moodle.

Worry?   Depends ... do you have any user from Japan who is an admin?

What clip you've shared shows a mobile device - IP address supposedly 49.109.102.44 - which according to whois is geographically Chiyoda-ku,Tokyo Japan.

Have any users in your Moodle from Japan? 

Have observed the same strange behavior after an upgrade ... first runs of cron at tail end adhoc-task which normally would report 0 and cron job finishes, instead goes into a loop for 180 attempts - during those the cron job actually runs again.   Eventually, if allowed to run it's course, the logs (DB tables) that track such things straighten out (for lack of a better term) and the next run of cron, executes as expected - with 0 adhoc.

It's odd!

Add the path to php-cli in PATH's config of your moodle.
Then go the task list ... there you should see a 'run now' underneath those jobs that are active.     Clicking 'run now' will run only that task - not the entire cron job.

In looking at that chart of task ... see which ones might have failed to complete ... and try those.

Also ... some of the jobs might involved notifications to admins ... might turn off the notifications to admins for failed logins for a while.   That should reduce the number of emails sent.

Email notifications is also another area one should review/inspect/test.

'SoS', Ken

Average of ratings: Useful (1)
In reply to Aaron Stockdale

Re: Ad hoc tasks not running / fails in task logs

by Aaron Stockdale -
When trying to run cron via cli, I get the following error:


---------------------------------------------------------------------
PHP Deprecated: Creation of dynamic property cache_config::$configlockmappings is deprecated in /var/www/moodle/cache/classes/config.php on line 146
Server Time: Fri, 15 Mar 2024 09:35:27 -0600


Execute scheduled task: Cleanup contexts (core\task\context_cleanup_task)
!!! Exception - Class "IntlTimeZone" not found !!!
--------------------------------------------------------------------------



I get this same error when trying to run any of the scheduled tasks that show up as Failed in the Task Logs

When I try to run the adhoc tasks via cli I get this:


----------------------------------------------------------------------------
PHP Deprecated: Creation of dynamic property cache_config::$configlockmappings is deprecated in /var/www/moodle/cache/classes/config.php on line 146
Server Time: Fri, 15 Mar 2024 09:43:42 -0600

Execute adhoc task: assignfeedback_editpdf\task\convert_submission
Adhoc task id: 8271
Adhoc task custom data: {"submissionid":"8238","submissionattempt":"1"}
!!! Coding error detected, it must be fixed by a programmer: A lock was created but not released at:
[dirroot]/lib/cronlib.php on line 154

Code should look like:

$factory = \core\lock\lock_config::get_lock_factory('type');
$lock = $factory->get_lock(709937f245ddec70ed665f995e47c9858dd6d40e);
$lock->release(); // Locks must ALWAYS be released like this.

!!!
--------------------------------------------------------------------------------------
In reply to Aaron Stockdale

Re: Ad hoc tasks not running / fails in task logs

by Ken Task -
Picture of Particularly helpful Moodlers
Key hint ... "Depreciated...".  Have asked for version of Moodle and now have to ask for version of PHP - for web and php-cli.

See the chart:
http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases
look for your moodle version row and note the range of PHP versions.

'SoS', Ken

Average of ratings: Useful (1)
In reply to Ken Task

Re: Ad hoc tasks not running / fails in task logs

by Aaron Stockdale -
Moodle 4.1.9
PHP cli 8.3.2
PHP web 8.0.30

Things are making alot more sense thanks to your link. I will have to look at downgrading somehow.
In reply to Aaron Stockdale

Re: Ad hoc tasks not running / fails in task logs

by Ken Task -
Picture of Particularly helpful Moodlers
php-cli is really an extension.   So package manager should be able to make light work of that! smile

Have to remove php-cli - but don't let package manager erase anything but that - don't follow dependencies.

Package managers ... yum, dnf, apt-get - depends upon OS you are running.

'SoS', Ken

'
Average of ratings: Useful (1)
In reply to Ken Task

Re: Ad hoc tasks not running / fails in task logs

by Aaron Stockdale -
8.0 was still installed so switching back was very easy in Ubuntu 22.04:

sudo update-alternatives --config php

Then, for some reason, I had to set the nextruntime to the remaining adhoc task to the near future to get them to run. I had seen this trick in other forum posts, but never needed to do this before when running cron manually during this ordeal.

Anyways, thanks Ken and Jason for the help.
In reply to Aaron Stockdale

Re: Ad hoc tasks not running / fails in task logs

by Ken Task -
Picture of Particularly helpful Moodlers
So does that mean issue is resolved?

Might add 'SOLVED' to the front of the subject line if it is! smile

'SoS', Ken