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 char
12       *function_name, size_t function_name_length, const char *unique, size_t
13       unique_length, gearman_work_t *workload, gearman_argument_t *arguments,
14       void *context)
15
16       gearman_task_st         *gearman_execute_by_partition(gearman_client_st
17       *client,  const  char *partition_function, const size_t partition_func‐
18       tion_length,   const   char   *function_name,   const   size_t    func‐
19       tion_name_length,  const  char *unique_str, const size_t unique_length,
20       gearman_work_t *workload, gearman_argument_t *arguments, void *context)
21
22       Link with -lgearman
23

DESCRIPTION

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

RETURN VALUE

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

EXAMPLE

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

HOME

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

SEE ALSO

118       gearmand(8) libgearman(3)
119

AUTHOR

121       Data Differential http://www.datadifferential.com/
122
124       2011-2014, Data Differential, http://www.datadifferential.com/
125
126
127
128
1291.1.20                           Nov 19, 2022               GEARMAN_EXECUTE(3)
Impressum