1

How can I write drupal cron job that fetches data from a link and update the database ..? Im new to drupal so unable to understand the working of cron after searching alot. Any help will be appreciated ..

  • 1
    You should state your Drupal version... is the data of the link formatted in json, xml, csv? or what? – No Sssweat Aug 4 '16 at 5:32
  • @No Sssweat Im working on drupal 7.x .. data is coming in json format – Umair Yousaf Aug 4 '16 at 5:50
  • Welcome to Drupal Answers! It's not clear if you are asking how to fetch data from an external source, or which hook you need to implement, but in the first case, the question is too broad, and in the second case the answer can be easily found on api.drupal.org. Just search for cron and any of those listed functions give you a hint about what hook to implement. – kiamlaluno Aug 4 '16 at 12:19
1

Create a simple Drupal 7 module, there are a lot of examples for this (i.e. here). Then hook into cron with a function mymodulename_cron() and inside the mymodule_cron function fetch your json data.

Your mymodulename_cron() will be executed each time, the drupal cron is run. This can be done from outside or from the admin/reports page. Look at /admin/reports/status for info about this.

  • thanx @Rainer Feike .. I've created custom module and implemented hook_cron. My hook is working well when I click on run cron from admin interface. I want this hook to execute automatically right after one hour. But im unable to do it. Could you plz guide me how to accomplish this task? – Umair Yousaf Aug 4 '16 at 9:28
  • You can call the cron.php of your site from outside, i.e. use unix-cron and wget. Depends on your deployment env. – Rainer Feike Aug 4 '16 at 10:50
  • Or you go to /admin/config/system/cron and set the drop-down to 1 hour :-) – Rainer Feike Aug 4 '16 at 10:52

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