I have a custom module which migrates articles from a remote xml file. Because the RSS feed changes, I want my Drupal site to be in sync with the RSS feed. How do add e.g this command drush mim xml_content to my cron job, so it will update by each cron interval?

Or how do I add it to my custom module with hook_cron()?


While it's certainly possible programmatically invoke a Drush command in a custom hook handler (via drush_invoke_process()), you shouldn't do this.

Cron tasks are designed to handle periodic, smallish, update tasks on hourly, or sub-hourly, intervals. Migration jobs can get pretty I/O heavy so you shouldn't couple them on the same schedule as ongoing cron maintenance, lest you add potential instability based on some outside service/feed.

You should add a new cron job to your cron runner (e.g. crontab, Jenkins, etc.) that executes the drush mim xml_content on its own schedule. Depending on where your cron system is, the cron job will evoke drush mim xml_content or drush @host-alias mim xml_content (if your cron runner is outside the Drupal host machine).

| improve this answer | |

Your Answer

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

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