Score:0

hook_cron triggered manually but not automatically

za flag

That hook cron below is executed when i manually trigger the cron but is not on a regular automatic base (every 3h).

How can it be ?

function my_module_cron() {    
  \Drupal::logger('my_module')->notice('entering hook_cron');
  //some more code
}
 
cn flag
You need to schedule that yourself. Drupal has an automated cron module built in but it's a "best effort" and relies on traffic and is unreliable. People normaly use a simple crontab on their server for this, but there are any number of solutions out there
Matoeil avatar
za flag
@Clive could u please list a few possible options ? are there some options not requiring server configuration? using simple_cron or ultimate cron module maybe ?
cn flag
On-server is the best approach, next best is a service like pingdom. You can't schedule jobs through PHP, so you need something external to trigger it. If your task isn't critical, and can be delayed, you might be able to use the core automated cron and take the hit. Other modules won't help, they suffer from the same problem. If the task it critical/important, use an external service
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.