automating_job_execution.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. Automating Job Execution
  2. ========================================
  3. 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:
  4. .. image:: automating_job_execution.cron.png
  5. .. warning::
  6. 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.
  7. Also, on that page is the URL for cron. In this example the URL is http://localhost/cron.php?cron_key=pnwI1cni8wjX1tVPOBaAJmoGOrzDsFQCW_7pw.
  8. To add an entry to the UNIX cron we must use the crontab tool:
  9. .. code-block:: bash
  10. sudo crontab -e
  11. Add this line to the crontab:
  12. .. code-block:: bash
  13. 0,30 * * * * /usr/bin/wget -O - -q http://localhost/cron.php?cron_key=pnwI1cni8wjX1tVPOBaAJmoGOrzDsFQCW_7pwVHhigE
  14. 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.
  15. Automating Tripal Tasks
  16. -----------------------
  17. 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.
  18. Option #1: Manual Execution of Jobs
  19. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  20. 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:
  21. .. code-block:: bash
  22. drush trp-run-jobs --username=administrator --root=/var/www/html
  23. Remember to change the username from **administrator** to the name of the administrator on your site and change **/var/www/html** to the location where your site installed on the server.
  24. Option #2: Additional Cron Entry
  25. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  26. 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:
  27. .. code-block:: bash
  28. udo crontab -e
  29. Add this line to the crontab:
  30. .. code-block:: bash
  31. 0,5,10,15,20,25,30,35,40,45,50,55 * * * * drush trp-run-jobs --username=administrator --root=/var/www/html
  32. Here, job execution will occur every 5 minutes.
  33. Option #3: Tripal Daemon Setup
  34. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  35. 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:
  36. .. code-block:: bash
  37. drush pm-enable tripal_daemon
  38. 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.