Why cron jobs are only executed when I open the admin/cron.php page?

Why cron jobs are only executed when I open the admin/cron.php page?

by muzaki azami -
Number of replies: 9

I am using XAMPP for that matter. The cron jobs doesn't run (but they're already in the 'queue' for that matter) unless I access the 'cron.php' page.


On a side note, I've seen 'timeout limit' on the cron.php page, and it's 120. Can I raise it (I heard it's that low because I'm running the moodle on XAMPP Apache server)? Because transferring large files would obviously need more than that.



Average of ratings: -
In reply to muzaki azami

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by Séverin Terrier -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Testers Picture of Translators
Hi,

Did you setup your cron correctly, as explained in the Moodle cron documentation?

Séverin
In reply to Séverin Terrier

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by muzaki azami -
Which part I should be looking at?

Is it the "Setting up cron on your system" ? Since I use XAMPP, I clicked on this : https://docs.moodle.org/311/en/Cron_with_Windows_OS

And I've gotta say, I'm quite unsure about what I should do, since on the "Cron in Windows 10/Xampp environment" segment, it's noted that "Using wget or MoodleCron is difficult and uncertain"
In reply to muzaki azami

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Hi

You wrote:
> I am using XAMPP for that matter. The cron jobs doesn't run (but they're already in the 'queue' for that matter) unless I access the 'cron.php' page.

You mean, you visit a page like something/admin/cron.php in your browser, then you see the output of the cron.php script? If so,
a) what is the "something" in the URL?
b) could you post the output of cron.php? If too long, please copy-and-paste the beginning and end and also snippets where there are errors or warnings.

> On a side note, I've seen 'timeout limit' on the cron.php page, and it's 120. Can I raise it (I heard it's that low because I'm running the moodle on XAMPP Apache server)?

I think timeouts in cron.php are relevant. Can you show us those, true copy-and-paste?

> Because transferring large files would obviously need more than that.

cron.php transferring files? Never seen that. Do you want to say, your server is too weak to finish cron tasks? Yes, that will lead to big problems. If your server is too weak, then it is too weak. The developers (we are in the General developer forum) can't help you.

P.S. Saw this https://moodle.org/mod/forum/discuss.php?d=432113#p1738573. Have you changed Moodle code?

FYI: Unless you tell exactly what you are doing (and did) and provide evidence (copy-and-paste, screen-shots) the helpers are in the darkness.

In reply to Visvanath Ratnaweera

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by muzaki azami -
Oh sorry. To give context, I am creating an Activity Module that's supposed to send a file which the user uploaded (through background task) during the creation of its instance.

However, the background task wouldn't execute unless I access the 'localhost/moodle/admin/cron.php' page. 

In regards to timeouts, I can't seem to replicate it. I'm sorry (IIRC it was some h5p task, not my module's, and it failed because it exceeds the 120 sec limit). That being said, I am glad that it is dependent on the server's capability. I am developing the app on my own laptop (with XAMPP no less), but on a real use case scenario, the module would probably be used on a real server so timeout wouldn't be an issue.

And the output of the cron.php is pretty normal:
Server Time: Sun, 27 Feb 2022 03:03:26 +0100


Execute scheduled task: Background processing for tags (core\task\tag_cron_task)
... started 03:03:26. Current memory use 21.6MB.
... used 6 dbqueries
... used 0.97955679893494 seconds
Scheduled task complete: Background processing for tags (core\task\tag_cron_task)
Execute scheduled task: Cohort enrolment sync task (enrol_cohort\task\enrol_cohort_sync)
... started 03:03:28. Current memory use 22.6MB.
... used 7 dbqueries
... used 0.052457094192505 seconds
Scheduled task complete: Cohort enrolment sync task (enrol_cohort\task\enrol_cohort_sync)
Execute scheduled task: Cleanup old sessions (core\task\session_cleanup_task)
... started 03:03:28. Current memory use 23.2MB.
... used 7 dbqueries
... used 0.032294034957886 seconds
Scheduled task complete: Cleanup old sessions (core\task\session_cleanup_task)
Execute scheduled task: Send new user passwords (core\task\send_new_user_passwords_task)
... started 03:03:28. Current memory use 23.5MB.
... used 1 dbqueries
... used 0.0026578903198242 seconds
Scheduled task complete: Send new user passwords (core\task\send_new_user_passwords_task)
Execute scheduled task: Send failed login notifications (core\task\send_failed_login_notifications_task)
... started 03:03:28. Current memory use 23.5MB.
... used 0 dbqueries
... used 0.00016593933105469 seconds
Scheduled task complete: Send failed login notifications (core\task\send_failed_login_notifications_task)
Execute scheduled task: Legacy cron processing for plugins (core\task\legacy_plugin_cron_task)
... started 03:03:29. Current memory use 23.5MB.
Running auth crons if required...
Running enrol crons if required...
Starting activity modules
Finished activity modules
Starting blocks
Finished blocks
Starting admin reports
Finished admin reports
Starting course reports
Finished course reports
Starting gradebook plugins
Finished gradebook plugins
... used 2 dbqueries
... used 0.072503089904785 seconds
Scheduled task complete: Legacy cron processing for plugins (core\task\legacy_plugin_cron_task)
Execute scheduled task: Background processing for assignment module (mod_assign\task\cron_task)
... started 03:03:29. Current memory use 30.3MB.
... used 3 dbqueries
... used 0.095720052719116 seconds
Scheduled task complete: Background processing for assignment module (mod_assign\task\cron_task)
Execute scheduled task: Forum mailings and maintenance jobs (mod_forum\task\cron_task)
... started 03:03:29. Current memory use 34.5MB.
Removing old digest records from 7 days ago.
Removed all old digest records.
Fetching unmailed posts.
  No posts found.
... used 2 dbqueries
... used 0.27527093887329 seconds
Scheduled task complete: Forum mailings and maintenance jobs (mod_forum\task\cron_task)
Execute scheduled task: Background processing for gradebook (core\task\grade_cron_task)
... started 03:03:30. Current memory use 34.5MB.
... used 2 dbqueries
... used 0.031793117523193 seconds
Scheduled task complete: Background processing for gradebook (core\task\grade_cron_task)
Execute scheduled task: Updating overdue quiz attempts (mod_quiz\task\update_overdue_attempts)
... started 03:03:30. Current memory use 38.2MB.
  Looking for quiz overdue quiz attempts...
  Considered 0 attempts in 0 quizzes.
... used 1 dbqueries
... used 0.42797780036926 seconds
Scheduled task complete: Updating overdue quiz attempts (mod_quiz\task\update_overdue_attempts)
Execute scheduled task: Legacy cron quiz reports (mod_quiz\task\legacy_quiz_reports_cron)
... started 03:03:31. Current memory use 38.2MB.
... used 0 dbqueries
... used 0.00057482719421387 seconds
Scheduled task complete: Legacy cron quiz reports (mod_quiz\task\legacy_quiz_reports_cron)
Execute scheduled task: Legacy cron quiz access rules (mod_quiz\task\legacy_quiz_accessrules_cron)
... started 03:03:31. Current memory use 38.2MB.
... used 0 dbqueries
... used 0.0005500316619873 seconds
Scheduled task complete: Legacy cron quiz access rules (mod_quiz\task\legacy_quiz_accessrules_cron)
Execute scheduled task: Calculate regular completion data (core\task\completion_regular_task)
... started 03:03:31. Current memory use 38.2MB.
Running completion_criteria_date->cron()
Running completion_criteria_activity->cron()
Running completion_criteria_duration->cron()
Running completion_criteria_grade->cron()
Running completion_criteria_course->cron()
Aggregating completions
... used 6 dbqueries
... used 0.03792405128479 seconds
Scheduled task complete: Calculate regular completion data (core\task\completion_regular_task)
Execute scheduled task: Background processing for portfolio plugins (core\task\portfolio_cron_task)
... started 03:03:31. Current memory use 38.5MB.
... used 0 dbqueries
... used 0.00027608871459961 seconds
Scheduled task complete: Background processing for portfolio plugins (core\task\portfolio_cron_task)
Execute scheduled task: Background processing for legacy cron in plagiarism plugins (core\task\plagiarism_cron_task)
... started 03:03:32. Current memory use 38.5MB.
... used 0 dbqueries
... used 0.00017595291137695 seconds
Scheduled task complete: Background processing for legacy cron in plagiarism plugins (core\task\plagiarism_cron_task)
Execute scheduled task: Background processing for workshop module (mod_workshop\task\cron_task)
... started 03:03:32. Current memory use 38.5MB.
 processing workshop subplugins ...
... used 1 dbqueries
... used 0.099501848220825 seconds
Scheduled task complete: Background processing for workshop module (mod_workshop\task\cron_task)
Execute scheduled task: Send calendar notifications (core\task\calendar_cron_task)
... started 03:03:32. Current memory use 38.6MB.
... used 1 dbqueries
... used 0.023709058761597 seconds
Scheduled task complete: Send calendar notifications (core\task\calendar_cron_task)
Execute scheduled task: Sync external blogs (core\task\blog_cron_task)
... started 03:03:32. Current memory use 39MB.
... used 2 dbqueries
... used 0.048816919326782 seconds
Scheduled task complete: Sync external blogs (core\task\blog_cron_task)
Execute scheduled task: Legacy cron workshop allocation (mod_workshop\task\legacy_workshop_allocation_cron)
... started 03:03:32. Current memory use 39.3MB.
... used 0 dbqueries
... used 0.00058412551879883 seconds
Scheduled task complete: Legacy cron workshop allocation (mod_workshop\task\legacy_workshop_allocation_cron)
Execute scheduled task: Incoming email pickup (tool_messageinbound\task\pickup_task)
... started 03:03:33. Current memory use 39.8MB.
Inbound Message not fully configured - exiting early.
... used 0 dbqueries
... used 0.0021231174468994 seconds
Scheduled task complete: Incoming email pickup (tool_messageinbound\task\pickup_task)
Execute scheduled task: Background processing for cleaning up question previews (core\task\question_preview_cleanup_task)
... started 03:03:33. Current memory use 40MB.

  Cleaning up old question previews...done.
... used 2 dbqueries
... used 0.020812034606934 seconds
Scheduled task complete: Background processing for cleaning up question previews (core\task\question_preview_cleanup_task)
Execute scheduled task: Background processing for cleaning up question statistics caches (core\task\question_stats_cleanup_task)
... started 03:03:33. Current memory use 40MB.

  Cleaning up old question statistics cache records...done.
... used 4 dbqueries
... used 0.23007321357727 seconds
Scheduled task complete: Background processing for cleaning up question statistics caches (core\task\question_stats_cleanup_task)
Execute scheduled task: Cleanup event monitor events (tool_monitor\task\clean_events)
... started 03:03:34. Current memory use 40MB.
... used 0 dbqueries
... used 0.00061798095703125 seconds
Scheduled task complete: Cleanup event monitor events (tool_monitor\task\clean_events)
Execute scheduled task: Background processing for scheduled allocation (workshopallocation_scheduled\task\cron_task)
... started 03:03:34. Current memory use 40MB.
... no workshops awaiting scheduled allocation. ... used 1 dbqueries
... used 0.31064915657043 seconds
Scheduled task complete: Background processing for scheduled allocation (workshopallocation_scheduled\task\cron_task)
Execute adhoc task: mod_cheve\task\send_to_ws
... started 03:03:34. Current memory use 40.1MB.
... used 1 dbqueries
... used 0.037688970565796 seconds
Adhoc task complete: mod_cheve\task\send_to_ws
Ran 1 adhoc tasks found at Sun, 27 Feb 2022 03:03:26 +0100
Cron script completed correctly
Cron completed at 03:03:35. Memory used 40.3MB.
Execution took 8.708572 seconds


In reply to muzaki azami

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
> However, the background task wouldn't execute unless I access the 'localhost/moodle/admin/cron.php' page.

Did you read the Moodle cron documentatin to which Séverin has provided the link?

Talking of XAMPP https://www.apachefriends.org/, I assume you mean the Windows package - and an ancient one or you know how to juggle its components, for example Moodle is not PHP 8 compatible yet.

In reply to Visvanath Ratnaweera

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by muzaki azami -
I have but I'm quite unsure how to setup it for XAMPP.

I am looking at : https://docs.moodle.org/311/en/Cron_with_Windows_OS
by the way, because for the XAMPP segment it pretty much said the above lengthy steps are unreliable...
In reply to muzaki azami

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
Now I got it! XAMPP means Windows platform for you. I entered the discussion without knowing. You didn't say that in your OP.

Sorry, I am clueless on Microsoft topics. My only observation is, if "it pretty much said the above lengthy steps are unreliable..." why don't you go for a reliable platform, like Linux, as a developer?

In reply to muzaki azami

Re: Why cron jobs are only executed when I open the admin/cron.php page?

by AL Rachels -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I've had a Moodle site running on XAMP for development for a few years that originally started out as Moodle 3.2, if my memory is correct. I side loaded it to use git for updates and sort of side load the whole XAMP to upgrade it four times. I have also moved the moodledata folder out of the moodle root file. Anyway, today I just upgraded the Moodle code from Moodle 3.10.9+ to Moodle 3.11.5+. In the past, I never worried about running cron for this Moodle as I have other sites where I check stuff that depends on cron. However, just to let you know, the MoodleCron-Setup you link too above, does work. My first attempt, I did try to set it for 1 minute like Moodle recommends, but could not get it to work. Took a while to get it to uninstall and try again, but I do have it running about every two minutes now.
Average of ratings: Useful (1)