0

I created webform and saving submitted data into text file in drupal files folder. A remote script performs calculations and outputs new text file to the same folder . I want cron to run everytime text file is generated, so that i can print result from text file to webform and also save them to database

So far i created custom module for webform and used hook_cron() as shown below

function simulation_ignition_view_cron()
 {
  $uri = 'default/files/simulation/generatedfile.txt';
  if (file_exists($uri)) {
  drupal_set_message("hello cron");
 }
}

Please let me know if my explanation is not clear and please give some suggestions

1 Answer 1

1

I want cron to run everytime text file is generated

I think you're misunderstanding what cron is. Cron is

a command to an operating system or server for a job that is to be executed at a specified time.

It doesn't respond to file system triggers, it's a scheduled task.

If a file is created as part of the normal Drupal content add/edit, you can just implement hook_file_insert():

function MYMODULE_file_insert($file) {
  if ($file->uri == 'foo') {
    // Do something.
  }
}

If you want to start the scheduled jobs running in that hook you can use drupal_cron_run(), but it would probably make more sense not to involve cron in this.

1
  • Thanks for you reply . I will try using hook_file_insert
    – Naveena
    Commented Aug 27, 2014 at 13:34

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.