automating_job_execution.rst 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. Automating Job Execution
  2. ========================================
  3. .. note::
  4. Remember you must set the ``$DRUPAL_HOME`` environment variable if you want to cut-and-paste the commands below. See :doc:`./drupal_home`
  5. The Drupal cron is used to automatically execute necessary Drupal housekeeping tasks on a regular interval. You should *always* setup the Drupal cron to ensure your site checks for updates and security issues. To do this, we want to integrate Drupal cron with the UNIX cron facility. The UNIX cron will automatically execute commands on set regular intervals. First, we must get the appropriate URL for the cron by navigating to **Configuration → Cron**. On this page you will see a link that we will use for cron:
  6. .. image:: automating_job_execution.cron.png
  7. .. warning::
  8. Be sure to edit the settings on the page and set the drop down value titled Run Cron Every to Never and save the configuration. If we do not set this to Never then Drupal will run cron when user's visit the site and that may cause slowness.
  9. Also, on that page is the URL for cron. In this example the URL is http://localhost/cron.php?cron_key=pnwI1cni8wjX1tVPOBaAJmoGOrzDsFQCW_7pw.
  10. To add an entry to the UNIX cron we must use the crontab tool:
  11. .. code-block:: bash
  12. sudo crontab -e
  13. Add this line to the crontab:
  14. .. code-block:: bash
  15. 0,30 * * * * /usr/bin/wget -O - -q http://localhost/cron.php?cron_key=pnwI1cni8wjX1tVPOBaAJmoGOrzDsFQCW_7pwVHhigE
  16. Now save the changes. We have now added a UNIX cron job that will occur every 30 minutes that will execute the cron.php script and cause Drupal to perform housekeeping tasks.
  17. Automating Tripal Tasks
  18. -----------------------
  19. Many of the tasks that Tripal needs to perform can take some time to run. Examples include loading of ontologies, publishing content, and importing data. It is not practical for these tasks to run within the web browser. Therefore, Tripal provides a jobs management system. When long-running tasks need execution a job is submitted and it waits in a queue until it is executed. There are several methods that can be used to help ensure jobs can be executed in a timely manner.
  20. Option #1: Manual Execution of Jobs
  21. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  22. Any job that is added to the Job's system can be run manually on the command line using a Drush command. Throughout this tutorial instructions are provided to execute jobs manually. Jobs in the queue can be executed using a Drush command similar to the following:
  23. .. code-block:: bash
  24. drush trp-run-jobs --username=administrator --root=$DRUPAL_HOME
  25. Remember to change the username from **administrator** to the name of the administrator on your site.
  26. Option #2: Additional Cron Entry
  27. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  28. If you do not want to manually run every job that is added to Tripal's job system you can automate execution of the job by using the same cron system that Drupal uses for housekeeping steps. To do so, use the crontab Command to add a new line to the bottom of the cron setup:
  29. .. code-block:: bash
  30. udo crontab -e
  31. Add this line to the crontab:
  32. .. code-block:: bash
  33. 0,5,10,15,20,25,30,35,40,45,50,55 * * * * drush trp-run-jobs --username=administrator --root=$DRUPAL_HOME
  34. Here, job execution will occur every 5 minutes.
  35. Option #3: Tripal Daemon Setup
  36. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  37. Tripal version 3 has incorporated the Tripal Daemon module. This module was previously an extension but is now part of the Tripal package. The Tripal Daemon module will allow jobs to execute immediately upon submission, rather than waiting on the time set in the cron setup of option #2. This can be especially useful when end-users submit jobs such as with the Tripal Blast UI module. To enable the Tripal Daemon module use the following Drush command within your Drupal installation directory:
  38. .. code-block:: bash
  39. drush pm-enable tripal_daemon
  40. Further documentation for setup of the Tripal Daemon will appear here in the future. For now, please see the :doc:`Job Management </user_guide/job_management>` page for usage instructions.