running_jobs.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. Running your jobs
  2. =================
  3. Gearman provides a set of commands that will make easier to know all workers
  4. settings.
  5. .. code-block:: bash
  6. $ php app/console
  7. A subset of listed commands are Gearman specific.
  8. .. code-block:: bash
  9. gearman
  10. gearman:cache:clear Clears gearman cache data on current environment
  11. gearman:cache:warmup Warms up gearman cache data
  12. gearman:job:describe Describe given job
  13. gearman:job:execute Execute one single job
  14. gearman:worker:describe Describe given worker
  15. gearman:worker:execute Execute one worker with all contained Jobs
  16. gearman:worker:list List all Gearman Workers and their Jobs
  17. Listing workers and jobs
  18. ~~~~~~~~~~~~~~~~~~~~~~~~
  19. Once all your workers are defined, you can simply list them to ensure all
  20. settings are correct.
  21. .. code-block:: bash
  22. $ php app/console gearman:worker:list
  23. @Worker: Mmoreramerino\TestBundle\Services\AcmeWorker
  24. callablename: MmoreramerinoTestBundleServicesMyAcmeWorker
  25. Jobs:
  26. - #1
  27. name: testA
  28. callablename: MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething
  29. Listing worker settings
  30. ~~~~~~~~~~~~~~~~~~~~~~~
  31. You can describe full worker using its callableName.
  32. This command provides you all information about desired Worker, overwritting
  33. custom annotation settings to default config settings.
  34. This command also provides you all needed information to work with Supervisord.
  35. .. code-block:: bash
  36. $ php app/console gearman:worker:describe MmoreramerinoTestBundleServicesMyAcmeWorker
  37. @Worker\className : Mmoreramerino\TestBundle\Services\AcmeWorker
  38. @Worker\fileName : /var/www/projects/myrepo/src/Mmoreramerino/TestBundle/Services/AcmeWorker.php
  39. @Worker\nameSpace : Mmoreramerino\TestBundle\Services
  40. @Worker\callableName: MmoreramerinoTestBundleServicesMyAcmeWorker
  41. @Worker\supervisord : /usr/bin/php /var/www/projects/myrepo/app/console gearman:worker:execute MmoreramerinoTestBundleServicesMyAcmeWorker --no-interaction
  42. @worker\iterations : 3
  43. @Worker\#jobs : 1
  44. @worker\servers :
  45. #0 - 192.168.1.1:4560
  46. #1 - 192.168.1.2:4560
  47. @Worker\description :
  48. Acme Worker. Containing multiple available jobs
  49. Listing job settings
  50. ~~~~~~~~~~~~~~~~~~~~
  51. You can also describe full job using also its callableName
  52. This command provides you all information about desired Job, overwritting custom
  53. annotation settings to worker settings.
  54. This command also provides you all needed information to work with Supervisord.
  55. .. code-block:: bash
  56. $ php app/console gearman:job:describe MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething
  57. @Worker\className : Mmoreramerino\TestBundle\Services\AcmeWorker
  58. @Worker\fileName : /var/www/projects/myrepo/src/Mmoreramerino/TestBundle/Services/AcmeWorker.php
  59. @Worker\nameSpace : Mmoreramerino\TestBundle\Services
  60. @Worker\callableName: MmoreramerinoTestBundleServicesMyAcmeWorker
  61. @Worker\supervisord : /usr/bin/php /var/www/projects/myrepo/app/console gearman:worker:execute MmoreramerinoTestBundleServicesMyAcmeWorker --no-interaction
  62. @worker\iterations : 3
  63. @Worker\#jobs : 1
  64. @worker\servers :
  65. #0 - 192.168.1.1:4560
  66. #1 - 192.168.1.2:4560
  67. @Worker\description :
  68. Acme Worker. Containing multiple available jobs
  69. @job\methodName : testA
  70. @job\callableName : MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething
  71. @job\supervisord : /usr/bin/php /var/www/projects/myrepo/app/console gearman:job:execute MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething --no-interaction
  72. @job\iterations : 10
  73. @job\defaultMethod : doBackground
  74. @job\servers :
  75. 0 - 192.168.1.1:4560
  76. @job\description :
  77. #Acme Job action. This is just a description of a method that do something
  78. Run a job
  79. ~~~~~~~~~
  80. You can execute by command line an instance of a worker or a job.
  81. The difference between them is that an instance of a worker can execute any of
  82. their jobs, without assignning any priority to them, and a job only can run
  83. itself.
  84. .. code-block:: bash
  85. $ php app/console gearman:worker:execute MmoreramerinoTestBundleServicesMyAcmeWorker
  86. $ php app/console gearman:job:execute MmoreramerinoTestBundleServicesMyAcmeWorker~doSomething
  87. .. note:: By using callableName you can let Supervisord maintain alive a worker.
  88. When the job is executed as times as iterations is defined, will die,
  89. but supervisord will alive it again.
  90. You can have as many as worker instances as you want.
  91. Get some `Supervisord`_ info
  92. Request job status
  93. ~~~~~~~~~~~~~~~~~~
  94. With the Handle given if requesting a background job you can request the status
  95. of the job. The Method returns a JobStatus object placed in
  96. `Mmoreram\GearmanBundle\Module\JobStatus'
  97. .. code-block:: php
  98. $jobStatus = $gearman->getJobStatus($result);
  99. $jobIsKnown = $jobStatus->isKnown();
  100. $jobIsRunning = $jobStatus->isRunning();
  101. $jobIsFinished = $jobStatus->isFinished();
  102. /**
  103. * Also gives completion data
  104. */
  105. $completed = $jobStatus->getCompleted();
  106. $completionTotal = $jobStatus->getCompletionTotal();
  107. $completionPercent = $jobStatus->getCompletionPercent();
  108. .. _Supervisord: http://supervisord.org/