tripal_launch_job.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * This script will launch any waiting tripal jobs in succession.
  5. *
  6. * This script must be run at the base directory level of the drupal installation
  7. * in order to pick up all necessary dependencies
  8. */
  9. $stdout = fopen('php://stdout', 'w');
  10. // we require one command-line argument
  11. if (sizeof($argv) < 5) {
  12. print_usage($stdout);
  13. exit;
  14. }
  15. $job_id = $argv[1];
  16. $root = $argv[2];
  17. $username = $argv[3];
  18. $do_parallel = $argv[4];
  19. $max_jobs = (isset($argv[5]) ? $argv[5] : -1; // -1 = don't limit number of consecutive jobs
  20. /**
  21. * Root directory of Drupal installation.
  22. */
  23. define('DRUPAL_ROOT', getcwd());
  24. require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
  25. drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
  26. menu_execute_active_handler();
  27. $drupal_base_url = parse_url('http://www.example.com');
  28. $_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
  29. // $_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/index.php';
  30. $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
  31. $_SERVER['REMOTE_ADDR'] = NULL;
  32. $_SERVER['REQUEST_METHOD'] = NULL;
  33. $results = db_query("SELECT * FROM {users} WHERE name = :name", array(':name' => $username));
  34. $u = $results->fetchObject();
  35. if (!$u) {
  36. fwrite($stdout, "'$username' is not a valid Drupal username. exiting...\n");
  37. exit;
  38. }
  39. global $user;
  40. $user = user_load($u->uid);
  41. fwrite($stdout, "\n" . date('Y-m-d' H:i:s) . "\n");
  42. fwrite($stdout, "Tripal Job Launcher\n");
  43. fwrite($stdout, "Running as user ' . $username . '\n");
  44. fwrite($stdout, "-------------------\n");
  45. tripal_launch_job($do_parallel, null, $max_jobs);
  46. /**
  47. * Print out the usage instructions if they are not followed correctly
  48. *
  49. * @ingroup tripal_core
  50. */
  51. function print_usage($stdout) {
  52. fwrite($stdout, "Usage:\n");
  53. fwrite($stdout, " php tripal_launch_job <job_id> <drupal_root_path> <username> <do parallel>\n\n");
  54. fwrite($stdout, " where <username> is a Drupal user name\n\n");
  55. }