1

I ran into an issue recently where my hook_cron function was failing when triggered by cron. The problem was that I was calling EntityFieldQuery, which does access checks and since cron runs as an anonymous user, the query would to process correctly. Specifically, I was having this issue: EntityFieldQuery doesn't work correctly in hook_cron

I am trying to understand why cron runs as an anonymous user. Cron clears the cache and so has at least some database access. When writing hook_cron functions now, I have to bypass access checks so that they return results as expected. Does anyone understand why this is the intended behaviour?

Drupal 7

1 Answer 1

1

A cronjob should not have to be run by a specific drupal user. It sounds just like a maintenance task that should run sometimes to do something (send a part of a mail queue, clear some part of cache or whatever).

In some installs (all of mine, for example) run crons via drush/linux cronjob. cron_safe_threshold is set to 0 (never).

Typical tasks managed by hook_cron() are database maintenance, backups, recalculation of settings or parameters, automated mailing, and retrieving remote data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.