Cron job and Access Denied function I have a custom module which implements  hook_node_view() and checks certain conditions to decide whether a user can view the content or not. The code snippet is: 


    if( ! user_is_logged_in() && $node->type == "abc") {
        drupal_access_denied(); 
        module_invoke_all('exit'); 
        exit(); 
    }
    else {
        //do nothing
    }
}


The code works fine for me but the problem occurs when drupal's cron runs as Anonymous user. The only message I get is Attempting to re-run cron while it is already running. Could you please give me your suggestion to handle this.
hook_node_view() shouldn't be used for access checks, there's hook_node_access() for that sort of situation:

function MYMODULE_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : $node-&gt;type;
  if ($type == 'abc' &amp;&amp; $op == 'view') {
    return $account-&gt;uid &gt; 0;
  }
}


That'll handle the access check for the node gracefully, and shouldn't stop cron running halfway through.