Understanding Local Plugin and Cron

Understanding Local Plugin and Cron

by Suraj Kumar -
Number of replies: 3

I am using Moodle 2.7.7+. I have created a local plugin - programmanagement with following information in plugin's version.php. Also, I have added a function i,e. local_programmanagement_cron() in the lib.php of plugin.

//version.php

$plugin->version   = 2015090947;       // The current module version (Date: YYYYMMDDXX)

$plugin->requires  = 2014050800;    // Requires this Moodle version

$plugin->component = 'local_programmanagement'; // Full name of the plugin

$plugin->cron = 1;


I had the impression that whenever I would run localhost/mymoodle/admin/cron.php after passing the interval of 1(one) second, my cron of the plugin i,e. local_programmanagement_cron(), would get executed. Rather, It is getting executed on/after a larger interval. 


Can you please let me know why is this not running the cron script after the interval of 1(one) second? I am executing cron manually through url -  localhost/mymoodle/admin/cron.php

Although, I is recommended to implement task api for moodle version 2.7 onwards, however I want to know the reason of not executing the cron script of local plugin as expected.

Thanks in Advance.




Average of ratings: -
In reply to Suraj Kumar

Re: Understanding Local Plugin and Cron

by Suraj Kumar -
The Task APIs defines interval for cron job of the plugin. Is there any relevancy of $plugin->cron in version.php of the plugin then? Is there any conflicting situation If we are defining interval in both version.php and local_pluginname/db/task.php?


Any comment is highly appreciable.

In reply to Suraj Kumar

Re: Understanding Local Plugin and Cron

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

version.php defines how often the (legacy) cron function is called in the plugin. The tasks API defines how often each of the defined scheduled tasks are called.

In theory you could have both, with the cron function and the tasks doing different things (or the same thing being called from both - but then it would happen twice as often as intended). In reality, you want to stop using corn functions and just use tasks.

In reply to Davo Smith

Re: Understanding Local Plugin and Cron

by Suraj Kumar -

Thanks for replying Davo.

I implemented Task API for this plugin and it is running smoothly.  

Still, my concern is - why _cron() function was not getting executed after the defined cron-interval period as configured in version.php of plugin. It was running but after a larger interval that I am not able to guess for( approximately after 2-3 hours). Is there any setting  for setting-up a fixed interval of cron execution if TASK API not defined for the plugin.