1GEARMAN_EXECUTE(3)                 Gearmand                 GEARMAN_EXECUTE(3)
2
3
4

NAME

6       gearman_execute - Gearmand Documentation, http://gearman.info/
7

SYNOPSIS

9       #include <libgearman/gearman.h>
10
11       gearman_task_st    *gearman_execute(gearman_client_st *client,    const
12       char *function_name, size_t function_name_length,  const  char *unique,
13       size_t unique_length,      gearman_work_t *workload,      gearman_argu‐
14       ment_t *arguments, void *context)
15
16       gearman_task_st                     *gearman_execute_by_partition(gear‐
17       man_client_st *client,     const     char *partition_function,    const
18       size_t partition_function_length,  const   char *function_name,   const
19       size_t function_name_length,      const     char *unique_str,     const
20       size_t unique_length,      gearman_work_t *workload,      gearman_argu‐
21       ment_t *arguments, void *context)
22
23       Link with -lgearman
24

DESCRIPTION

26       gearman_execute()  is used to create a new gearman_task_st that is exe‐
27       cuted against the function that is found via  the  function_name  argu‐
28       ment.
29
30       gearman_work_t  can be used to describe the work that will be executed,
31       it is built with gearman_argument_make().  The argument  unique_str  is
32       optional, but if supplied it is used for coalescence by gearmand.
33
34       gearman_argument_t  is  the  work  that the client will send the to the
35       server
36
37       If gearman_execute() is given a gearman_work_t that has been built with
38       a  reducer,  it  takes  the gearman_argument_t and executs it against a
39       function as it normally would,  but  it  tells  the  function  to  then
40       process  the results through a reducer function that the gearman_work_t
41       was created with.
42
43       What is happening is that the function is  mappping/splitting  work  up
44       into units, and then sending each of them to the reducer function. Once
45       all work is completed, the mapper function will aggregate the work  via
46       an aggregator function, gearman_aggregator_fn, and return a result.
47
48       If any of the units of work error, the job will be aborted. The result‐
49       ing value will be stored in the gearman_task_st.
50
51       The  result  can  be  obtained  from  the   task   by   calling   gear‐
52       man_task_result() to gain the gearman_result_st.
53

RETURN VALUE

55       gearman_execute() returns a c:type:gearman_task_st.
56

EXAMPLE

58          /*
59            Example code to show how to send a string to a function called "reverse" and print the results.
60          */
61
62          /*
63          # Gearman server and library
64          # Copyright (C) 2012 Data Differential, http://datadifferential.com/
65          # All rights reserved.
66          #
67          # Use and distribution licensed under the BSD license.  See
68          # the COPYING file in this directory for full text.
69          */
70
71          #include <string.h>
72          #include <stdlib.h>
73          #include <stdio.h>
74          #include <libgearman/gearman.h>
75
76          int main(void)
77          {
78            gearman_client_st *client= gearman_client_create(NULL);
79
80            gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
81            if (gearman_failed(ret))
82            {
83              return EXIT_FAILURE;
84            }
85
86            gearman_argument_t value= gearman_argument_make(0, 0, "Reverse Me", strlen("Reverse Me"));
87
88            gearman_task_st *task= gearman_execute(client,
89                                                   "reverse", strlen("reverse"),  // function
90                                                   NULL, 0,  // no unique value provided
91                                                   NULL,
92                                                   &value, 0);
93
94            if (task == NULL) // If gearman_execute() can return NULL on error
95            {
96              fprintf(stderr, "Error: %s\n", gearman_client_error(client));
97              gearman_client_free(client);
98              return EXIT_FAILURE;
99            }
100
101            // Make sure the task was run successfully
102            if (gearman_success(gearman_task_return(task)))
103            {
104              // Make use of value
105              gearman_result_st *result= gearman_task_result(task);
106              printf("%.*s\n", (int)gearman_result_size(result), gearman_result_value(result));
107            }
108
109            gearman_client_free(client);
110
111            return EXIT_SUCCESS;
112          }
113
114

HOME

116       To find out more information please check: http://gearman.info/
117

SEE ALSO

119       gearmand(8) libgearman(3)
120

AUTHOR

122       Data Differential http://www.datadifferential.com/
123
125       2011-2014, Data Differential, http://www.datadifferential.com/
126
127
128
129
1301.1.19.1                         Feb 18, 2020               GEARMAN_EXECUTE(3)
Impressum