For the first time in a module I am implementing hook cron, like so:

function mymodule_cron(){

dpm("Cron fired");

watchdog("hook_cron","Mymodule cron process",NULL, WATCHDOG_INFO);

}

But nothing is happening when I run Cron.

In my node.tpl.php

I have used this snippet:

dpm(module_implements('cron'));

that proves that mymodule is one of those implementing cron, so I know it's seen...

What am I doing wrong?

Accepted answer

So reading the code in bootstrap.inc, I discovered that there is a check for the severity of notice, and ignoring anything not matching.

so after doing this in admin/config/development/logging; watchdog works:

Thanks again!

Most helpful answers

Echo will not output anything either. The output buffer is completely cleared with cron. Watchdog does work (for me at least). There may be something going on with your site.

Comments

I'm testing doing this in a custom module, and it's working for me. I put the implementation testing_stuff_cron() in testing_stuff.module.

dpm() will never produce any output when cron is run. However, watchdog should work. So, this is very strange, especially since the system is showing that your module is implementing the hook. Not sure what to tell you. Clear caches again and then run cron? 

Thanks mate, yeh, cleared caches, no difference. Went and manually emptied every cache table, no difference.
I tried an Echo instead of a dpm, as I thought they may not have fired, and still nothing...

So next up I will add my watchdog to an existing module _cron, and see if that is run. If it is then something very odd is going on...if not then cron is broken (although the update check regularly lets me know when new updates can be applied, so cron must be functional!)

So I added to the node module's existing cron...

 

/**

* Implements hook_cron().

*/

function node_cron() {

watchdog("hook_cron in node"," node module cron process",NULL, WATCHDOG_INFO);

Clear caches, run Cron, and that still doesn't fire off watchdog...

so maybe it is technically working, but watchdog is not the right choice in the cron hook?

Echo will not output anything either. The output buffer is completely cleared with cron. Watchdog does work (for me at least). There may be something going on with your site.

Try watchdog with only the first two parameters... Also try running watchdog() with exactly the same parameters in the PHP execute page at admin/devel/php and check. There may be something wrong with watchdog. 

Hmmm, so when I run the devel/php, this is all I see:

And still nothing added to the logs. I tried disabling, enabling the logging module, no difference.

So reading the code in bootstrap.inc, I discovered that there is a check for the severity of notice, and ignoring anything not matching.

so after doing this in admin/config/development/logging; watchdog works:

Thanks again!