gearman_worker_define_function.rst 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ======================================================
  2. Creating workers with gearman_worker_define_function()
  3. ======================================================
  4. --------
  5. SYNOPSIS
  6. --------
  7. #include <libgearman/gearman.h>
  8. .. c:type:: gearman_function_t
  9. .. c:function:: gearman_return_t gearman_worker_define_function(gearman_worker_st *worker, const char *function_name, const size_t function_name_length, const gearman_function_t function, const uint32_t timeout, void *context)
  10. .. c:type:: gearman_function_fn
  11. .. c:type:: gearman_aggregator_fn
  12. Link with -lgearman
  13. -----------
  14. DESCRIPTION
  15. -----------
  16. :c:func:`gearman_worker_define_function` defines functions for a worker.
  17. The interface is callback by design. When the server has a job for the worker, :c:type:`gearman_function_fn` is evoked with a :c:type:`gearman_job_st` representing the job, and the context that was defined originally when the function was defined.
  18. Results are sent back to the client by invoking :c:func:`gearman_job_send_data`.
  19. If the client specified an reducer function, then the output of the :c:type:`gearman_function_fn` will be sent to that function. You can split the work out to the reducer function by sending data multiple times with :c:func:`gearman_job_send_data`.
  20. If any errors are detected then the entire job is cancelled. The :c:type:`gearman_aggregator_fn` will
  21. be called when all mapped jobs have completed. The result of this function
  22. will be what is returned to the client.
  23. The callback function needs to return one of the following errors:
  24. :c:type:`GEARMAN_SUCCESS`
  25. The function was successful.
  26. :c:type:`GEARMAN_FAIL`
  27. An error has occurred, the job we not processed, and the worker cannot continue.
  28. :c:type:`GEARMAN_ERROR`
  29. A transient error has occurred, like a network failure, and the job can be restarted.
  30. If a value other then the above are returned it is converted to a :c:type:`GEARMAN_FAIL` and :c:func:`gearman_worker_work` returns :c:type:`GEARMAN_INVALID_ARGUMENT`.
  31. :c:func:`gearman_job_send_complete` and :c:func:`gearman_job_send_fail` cannot be used with any functions created with :c:func:`gearman_worker_define_function`.
  32. ------------
  33. RETURN VALUE
  34. ------------
  35. :c:type:`gearman_return_t`
  36. ----
  37. HOME
  38. ----
  39. To find out more information please check:
  40. `https://gearman.org/gearmand/ <https://gearman.org/gearmand/>`_
  41. --------
  42. SEE ALSO
  43. --------
  44. :manpage:`gearmand(8)` :manpage:`libgearman(3)` :manpage:`gearman_strerror(3)` :manpage:`gearman_client_error` :manpage:`gearman_client_execute_reduce`