customize.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Customize
  2. =========
  3. Some bundle behaviours can be overwritten
  4. Custom unique job identifier method
  5. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6. If you want a custom method to generate custom unique values for your jobs when
  7. not defined ( specified in generate_unique_key ), you only have to extend
  8. default UniqueJobIdentifierGenerator class and overwrite generateUniqueKey
  9. method, as folowing example.
  10. .. code-block:: php
  11. <?php
  12. /**
  13. * Gearman Bundle for Symfony2
  14. *
  15. * @author Marc Morera <yuhu@mmoreram.com>
  16. * @since 2013
  17. */
  18. namespace My\Custom\Namespace;
  19. use Mmoreram\GearmanBundle\Generator\UniqueJobIdentifierGenerator;
  20. /**
  21. * Gearman execute methods. All Worker methods
  22. *
  23. * @author Marc Morera <yuhu@mmoreram.com>
  24. */
  25. class MyCustomUniqueJobIdentifierGenerator extends UniqueJobIdentifierGenerator
  26. {
  27. /**
  28. * Generate unique key if generateUniqueKey is enabled
  29. *
  30. * $this->generateUniqueKey can be used as is protected in parent class
  31. *
  32. * @param string $name A GermanBundle registered function to be executed
  33. * @param string $params Parameters to send to task as string
  34. * @param string $unique unique ID used to identify a particular task
  35. * @param string $method Method to perform
  36. *
  37. * @return string Generated Unique Key
  38. */
  39. public function generateUniqueKey($name, $params, $unique, $method)
  40. {
  41. /**
  42. * Custom generation
  43. */
  44. }
  45. }
  46. You need also to overwrite in your config.yml the generator class
  47. .. code-block:: yml
  48. parameters:
  49. #
  50. # Generators
  51. #
  52. gearman.unique_job_identifier.class: My\Custom\Namespace\MyCustomUniqueJobIdentifierGenerator