Cron Job Issues

Re: Cron Job Issues

by Pawan Pandey -
Number of replies: 7
Hi there!

For your issue 1 and issue 2, things is this,
For marking course completion, Moodle utilize two task, core\task\completion_daily_task and another is core\task\completion_regular_task, so rather than running whole cron job at once, you can make one script . Following is same one


require_once('config.php');
require_once($CFG->dirroot.'/lib/classes/task/completion_regular_task.php');
require_once($CFG->dirroot.'/lib/classes/task/completion_daily_task.php');
try {
increment_revision_number('course', 'cacherev', '');
$obj = new core\task\completion_daily_task();
$obj->execute();
$obj = new core\task\completion_regular_task();
for ($i = 0 ; $i < 2; $i++) {
$obj->execute();
}
} catch (Exception $e) {
$obj->execute();
}

This script can help you to do course completion stuff, put this in place where it can run frequently, If you havent run cron for long time, then for first time, it will take time as it will create entry in {course_completions} table. Try above one.


For issue 3: I dont know.... sorry but i will research it and tell you.
Average of ratings: Useful (1)
In reply to Pawan Pandey

Re: Cron Job Issues

by Aye Min Htut -
Hi Pawan Pandey,

Thank you so much for your help. I'm trying to solve course completion problem. Your solution is working. But, please can you tell me where can I place your code? I tested it in "config.php and index.php". The config.php shows UI problems when I insert your code. Index.php needs to be refreshed the page. Sorry, I'm a beginner level coder. I need your help smile
In reply to Aye Min Htut

Re: Cron Job Issues

by Aye Min Htut -
Okay, I got it. I placed your script at the end of '/report/completion/lib.php'. Thanks smile
In reply to Aye Min Htut

Re: Cron Job Issues

by Pawan Pandey -
Hi ! make sure this script should be part of the file, which run frequently, I dont know how frequently you report/completion/lib.php will run, better is create one php file and run as cron job with 1~2min runtime,
Average of ratings: Useful (1)
In reply to Pawan Pandey

Re: Cron Job Issues

by Han Thet Nyein -
Hi Pawan, I don't know how to make it run in every 1~2min runtime. Please can you help me? After I use your script, my cron job is always running and I can't re-edit course completion setting again. Thanks ~
In reply to Han Thet Nyein

Re: Cron Job Issues

by Pawan Pandey -

Hi Han Thet Nyein

Breif: See provided script in above  is for marking course completion, when user complete the course.

Now it can be done by two ways. 

1. by running cron job... which apart from marking course complete perform lot of jobs. Which jobs and how frequently it to can be check in scheduled task settings in Moodle Site Administration. For this script to run i,e  in your moodle folder you have to run the script 

<moodlefolder>/admin/cli/cron.php

You can set it to run periodically. If you working on linux environment. USe following

vi /etc/crontab

In crontab add this entry

*/5 * * * /usr/bin/php /var/www/<moodlefolder>/admin/cli/cron.php

In windows, even i dont know.

2. Same thing is with custom  script. It run only specific job.

You can directly put path to above given script if you want to run via crontab in linux environment. But dont forget to add following line at top of script

define('CLI_SCRIPT', true);
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/clilib.php');

Note: The above are code add to run php file in moodle via CLI


Note: If you have lot of course in system, and lot of marking to be done... and depending upon your hardware where moodle is running. it may take time.

Average of ratings: Useful (1)
In reply to Pawan Pandey

Re: Cron Job Issues

by Han Thet Nyein -
Thank you Pawan Pandey for your detailed reply. I will try as you say. Thanks smile