1

Very strange problem that I cannot find anyone else having. I have a custom module and am using hook_cron(), but the cron job is not appearing in /admin/config/system/cron of my Drupal 7 site. All the other cron jobs I created through custom modules are there, and I did not think I did anything different.

Here is my function, in a file called file_handler.module

function file_handler_cron() {
   $log_file = '/www/anon_site.org/htdocs/sites/all/modules/custom/file_handler/log.txt';
   $log_file_size = exec("du -h $log_file", $output, $return_size);
   $size = substr($log_file_size, 0, strpos($log_file_size, '  '));   
   $measure = substr($size, -1);   //K, M, G, etc.
   $num = str_replace($measure, '', $size);  //4.0

   if ($measure == 'G' || $measure == 'T') {
       file_unmanaged_delete($path);
   }
   elseif ($measure == 'M' && $num > 10) {
       file_unmanaged_delete($path);
   }
   else {
       //log is small and does not need to be deleted
   }
}
  • I don't think D7 lists cron jobs on that page. Are you using a module to list the custom crons perhaps? – Beebee Nov 2 '17 at 11:50
  • Thanks for laying out the code in a readable format! Sorry this is my first ever stack exchange question. We are using Elysia cron. I have also tried using a hook_cronapi with the set parameters and again, no dice. My team members are really perplexed so I wondered if anyone else had an idea what the problem is. – dropintheocean Nov 2 '17 at 13:20
  • You should add Elysia Cron to the question, otherwise people may assume it's the bog standard poormanscron that comes with Drupal out of the box. – Beebee Nov 2 '17 at 15:35
  • Just an update that I tested this on the stage server and everything worked perfectly! So the dev server must have messed up configurations. Nothing wrong with the code for once. – dropintheocean Nov 6 '17 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.