What Exactly Happens when Drupal Cron Runs

Anyone that's worked with Drupal for some time is familiar with cron, but what what does it really do? Simple--Drupal invokes hook_cron() implementations found in all enabled modules. Cron is where each module can can perform periodic tasks either required for the module's functionality, or for maintenance purposes.

What your site does during cron depends on the modules you've got installed and how you've got them configured.

Core implementations of hook_cron().

  • Aggregator: Queues feeds to be updated.
  • Dblog (Watchdog): Controls the size of the log table, paring it to the configured row limit.
  • Field: Removes fields marked as not active (deleted).
  • Node: Updates the history status for "new" nodes.
  • Poll: Closes polls that have exceeded their allowed runtime.
  • Search: Updates the search index.
  • Statistics: Resets daily node view counter and removed expired access log records.
  • System: Cleans up expired flood records, deletes files marked as temporary and older than 6 hours, removes expired cache records, cleans up failed batches, and resets expired queue items.
  • Tracker: Updates node and user tracking data.
  • Trigger: Initiate actions set to for trigger on cron.
  • Update: Checks for updates to Drupal core and contrib projects and sends notification emails.

Contrib Implementations of hook_cron()

Contrib modules may implement hook_cron() to take care of their business as well. Here's a rundown on the tasks which some popular modules perform during a cron run.

  • Ctools: Cleans up old caches.
  • Feeds: Schedules feeds for update, expires old log entries.
  • Google Analytics: Updates tracking Javascript code.
  • Mollum: Expires old session data.
  • Rules: Invokes cron event for rules to act upon.
  • Scheduler: Publishes and up-publishes nodes based on scheduling configuration.
  • XML Sitemap: Regenerates sitemap XML files.

Cron Queues

Talk about hook_cron_queue_info()