How to implement a cron job for every minute and every 5 minutes? In D8 I programmed hook_cron. I tested it several times but I cannot see any log in the watchlog.

The name of the module is nncbt. The code is placed in nncbt.module.

Any suggestions what I should do?

function nncbt_cron() {  


    $last_run_per_minut = \Drupal::state()-&gt;get('nncbt.last_run', 0);
    // If 1 minutes passed since last time.
    if ((REQUEST_TIME - $last_run_per_minut) &gt; 60) {

        \Drupal::logger('nncbt')-&gt;info('Runnning Cron every 1 minut log');

        // Update last run.
        \Drupal::state()-&gt;set('nncbt.last_run', REQUEST_TIME);

    }   

    // Run the following every 5 minutes
    $last_run_per_5_minuts = \Drupal::state()-&gt;get('nncbt.last_run_5_minuts', 0);

    // If 5 minutes passed since last time.
    if ((REQUEST_TIME - $last_run_per_5_minuts) &gt; 300) {

        \Drupal::logger('nncbt')-&gt;info("Runnning Cron every 5 minut log");


        // Update last run.
        \Drupal::state()-&gt;set('nncbt.last_run_5_minuts', REQUEST_TIME);

    }

}
hook_cron() 


  The engine will then call the hook whenever a cron run happens, as
  defined by the administrator.


In other words, hook_cron gets executed after a cron run happens. So if you have cron set to run once a day, then your hook_cron script only gets executed once per day. So you need to set cron to run every 5 minutes or less.

A better alternative, I suggest you use a module like Ultimate   Cron which allows you to schedule different cron run times for different cron tasks. This way, cron doesn't run every single task every 5 minutes and instead it runs your specific task only.