job.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
  2. *
  3. * Gearmand client and server library.
  4. *
  5. * Copyright (C) 2011 Data Differential, http://datadifferential.com/
  6. * Copyright (C) 2008 Brian Aker, Eric Day
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are
  11. * met:
  12. *
  13. * * Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * * Redistributions in binary form must reproduce the above
  17. * copyright notice, this list of conditions and the following disclaimer
  18. * in the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * * The names of its contributors may not be used to endorse or
  22. * promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. */
  38. /**
  39. * @file
  40. * @brief Job Declarations
  41. */
  42. #pragma once
  43. struct gearman_job_st
  44. {
  45. struct {
  46. bool allocated;
  47. bool assigned_in_use;
  48. bool work_in_use;
  49. bool finished;
  50. } options;
  51. gearman_worker_st *worker;
  52. gearman_job_st *next;
  53. gearman_job_st *prev;
  54. gearman_connection_st *con;
  55. gearman_packet_st assigned;
  56. gearman_packet_st work;
  57. struct gearman_job_reducer_st *reducer;
  58. gearman_return_t error_code;
  59. };
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. /**
  64. * @addtogroup gearman_job Job Declarations
  65. * @ingroup gearman_worker
  66. *
  67. * The job functions are used to manage jobs assigned to workers. It is most
  68. * commonly used with the worker interface.
  69. *
  70. * @{
  71. */
  72. /**
  73. * Initialize a job structure. Always check the return value even if passing
  74. * in a pre-allocated structure. Some other initialization may have failed. It
  75. * is not required to memset() a structure before providing it.
  76. *
  77. * @param[in] A valid gearman_worker_st.
  78. * @param[in] gearman_job_st allocated structure, or NULL to allocate one.
  79. * @return On success, a pointer to the (possibly allocated) structure. On
  80. * failure this will be NULL.
  81. */
  82. GEARMAN_LOCAL
  83. gearman_job_st *gearman_job_create(gearman_worker_st *worker,
  84. gearman_job_st *job);
  85. /**
  86. * Free a job structure.
  87. *
  88. * @param[in] job Structure previously initialized with
  89. * gearman_worker_grab_job().
  90. */
  91. GEARMAN_API
  92. void gearman_job_free(gearman_job_st *job);
  93. /**
  94. * Send data for a running job.
  95. */
  96. GEARMAN_API
  97. gearman_return_t gearman_job_send_data(gearman_job_st *job,
  98. const void *data, size_t data_size);
  99. /**
  100. * Send warning for a running job.
  101. */
  102. GEARMAN_API
  103. gearman_return_t gearman_job_send_warning(gearman_job_st *job,
  104. const void *warning,
  105. size_t warning_size);
  106. /**
  107. * Send status information for a running job.
  108. */
  109. GEARMAN_API
  110. gearman_return_t gearman_job_send_status(gearman_job_st *job,
  111. uint32_t numerator,
  112. uint32_t denominator);
  113. /**
  114. * Send result and complete status for a job.
  115. */
  116. GEARMAN_API
  117. gearman_return_t gearman_job_send_complete(gearman_job_st *job,
  118. const void *result,
  119. size_t result_size);
  120. GEARMAN_LOCAL
  121. gearman_return_t gearman_job_send_complete_fin(gearman_job_st *job,
  122. const void *result, size_t result_size);
  123. /**
  124. * Send exception for a running job.
  125. */
  126. GEARMAN_API
  127. gearman_return_t gearman_job_send_exception(gearman_job_st *job,
  128. const void *exception,
  129. size_t exception_size);
  130. /**
  131. * Send fail status for a job.
  132. */
  133. GEARMAN_API
  134. gearman_return_t gearman_job_send_fail(gearman_job_st *job);
  135. GEARMAN_LOCAL
  136. gearman_return_t gearman_job_send_fail_fin(gearman_job_st *job);
  137. /**
  138. * Get job handle.
  139. */
  140. GEARMAN_API
  141. const char *gearman_job_handle(const gearman_job_st *job);
  142. /**
  143. * Get the function name associated with a job.
  144. */
  145. GEARMAN_API
  146. const char *gearman_job_function_name(const gearman_job_st *job);
  147. GEARMAN_LOCAL
  148. gearman_string_t gearman_job_function_name_string(const gearman_job_st *);
  149. /**
  150. * Get the unique ID associated with a job.
  151. */
  152. GEARMAN_API
  153. const char *gearman_job_unique(const gearman_job_st *job);
  154. GEARMAN_LOCAL
  155. gearman_string_t gearman_job_reducer_string(const gearman_job_st *job);
  156. GEARMAN_LOCAL
  157. const char *gearman_job_reducer(const gearman_job_st *job);
  158. GEARMAN_LOCAL
  159. bool gearman_job_is_map(const gearman_job_st *job);
  160. GEARMAN_LOCAL
  161. bool gearman_job_build_reducer(gearman_job_st *job, gearman_aggregator_fn *aggregator_fn);
  162. /**
  163. * Get a pointer to the workload for a job.
  164. */
  165. GEARMAN_API
  166. const void *gearman_job_workload(const gearman_job_st *job);
  167. /**
  168. * Get size of the workload for a job.
  169. */
  170. GEARMAN_API
  171. size_t gearman_job_workload_size(const gearman_job_st *job);
  172. /**
  173. * Take allocated workload from job. After this, the caller is responsible
  174. * for free()ing the memory.
  175. */
  176. GEARMAN_API
  177. void *gearman_job_take_workload(gearman_job_st *job, size_t *data_size);
  178. /** @} */
  179. #ifdef __cplusplus
  180. }
  181. #endif