GEARMAN_EXECUTE(3)

✨ NAME ✨

gearman_execute β€” okay bestie, this one's straight from the Gearmand documentation over at http://gearman.info/, and it lives in the GEARMAN_EXECUTE(3) manual. Yes it's a C library function and yes it's lowkey iconic. Let's get into it πŸ’–


🌸 SYNOPSIS 🌸

#include <libgearman/gearman.h>

gearman_task_st <#c.gearman_task_st> *gearman_execute(gearman_client_st
<#c.gearman_client_st> *client, const char *function_name, size_t <#c
.size_t> function_name_length, const char *unique, size_t <#c.size_t>
unique_length, gearman_work_t <#c.gearman_work_t> *workload,
gearman_argument_t <#c.gearman_argument_t> *arguments, void *context)

gearman_task_st <#c.gearman_task_st>
*gearman_execute_by_partition(gearman_client_st <#c.gearman_client_st>
*client, const char *partition_function, const size_t <#c.size_t>
partition_function_length, const char *function_name, const size_t <#c
.size_t> function_name_length, const char *unique_str, const size_t <#c
.size_t> unique_length, gearman_work_t <#c.gearman_work_t> *workload,
gearman_argument_t <#c.gearman_argument_t> *arguments, void *context)

And when you link it, you link with -lgearman 🫢 (don't forget it, she's necessary)


πŸ¦‹ DESCRIPTION πŸ¦‹

So gearman_execute() is the moment you make a brand-new gearman_task_st <#c.gearman_task_st> that gets executed against the function found through the function_name argument. That's the whole vibe ✨

A gearman_work_t <#c.gearman_work_t> can be used to describe the work that's gonna be executed β€” it's built with gearman_argument_make() <#c.gearman_argument_make>. The argument unique_str is optional, but if you do supply it, it gets used for coalescence by gearmand. Optional bestie, but she has a job πŸ’…

And the gearman_argument_t <#c.gearman_argument_t>? That's the work that the <term-client>client</term-client> will send to the server. Periodt.

Now here's where it gets main character energy: if gearman_execute() is given a gearman_work_t <#c.gearman_work_t> that's been built with a reducer, it takes that gearman_argument_t <#c.gearman_argument_t> and executes it against a <term-function>function</term-function> exactly like it normally would β€” but it tells the function to then process the results through a <term-reducer>reducer</term-reducer> function, the one the gearman_work_t <#c.gearman_work_t> was created with. Two modes, one function, we love a versatile icon 🌈

So what's actually happening under the hood? The function is mapping/splitting work up into units, and then sending each of those units to the reducer function. Once all the work is completed, the <term-mapper>mapper</term-mapper> function will aggregate the work via an aggregator function β€” gearman_aggregator_fn <#c.gearman_aggregator_fn> β€” and return a result. It's giving assembly line, but make it ✨ distributed ✨

🚨 Important, fr fr: if any of the units of work error, the job will be aborted. The resulting value gets stored in the gearman_task_st <#c.gearman_task_st>.

And to get that result out of the task, you call gearman_task_result() <#c.gearman_task_result> so you can gain the gearman_result_st <#c.gearman_result_st>. That's your prize, bestie πŸŽ€


πŸ’œ RETURN VALUE πŸ’œ

gearman_execute() returns a c:type:gearman_task_st.


πŸ‘‘ EXAMPLE πŸ‘‘

   /*
     Example code to show how to send a string to a function called "reverse" and print the results.
   */

   /*
   # Gearman server and library
   # Copyright (C) 2012 Data Differential, http://datadifferential.com/
   # All rights reserved.
   #
   # Use and distribution licensed under the BSD license.  See
   # the COPYING file in this directory for full text.
   */

   #include <string.h>
   #include <stdlib.h>
   #include <stdio.h>
   #include <libgearman/gearman.h>

   int main(void)
   {
     gearman_client_st *client= gearman_client_create(NULL);

     gearman_return_t ret= gearman_client_add_server(client, "localhost", 0);
     if (gearman_failed(ret))
     {
       return EXIT_FAILURE;
     }

     gearman_argument_t value= gearman_argument_make(0, 0, "Reverse Me", strlen("Reverse Me"));

     gearman_task_st *task= gearman_execute(client,
                                            "reverse", strlen("reverse"),  // function
                                            NULL, 0,  // no unique value provided
                                            NULL,
                                            &value, 0);

     if (task == NULL) // If gearman_execute() can return NULL on error
     {
       fprintf(stderr, "Error: %s\n", gearman_client_error(client));
       gearman_client_free(client);
       return EXIT_FAILURE;
     }

     // Make sure the task was run successfully
     if (gearman_success(gearman_task_return(task)))
     {
       // Make use of value
       gearman_result_st *result= gearman_task_result(task);
       printf("%.*s\n", (int)gearman_result_size(result), gearman_result_value(result));
     }

     gearman_client_free(client);

     return EXIT_SUCCESS;
   }

Like, look at her go πŸ₯Ή sending "Reverse Me" off to a function named "reverse" and printing whatever comes back. Chef's kiss.


🏠 HOME 🏠

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


πŸ” SEE ALSO πŸ”


🌟 Author 🌟

Data Differential http://www.datadifferential.com/

2011-2014, Data Differential, http://www.datadifferential.com/


Okay that's the whole page, bestie, you ate πŸ’… This was Gearmand docs, GEARMAN_EXECUTE(3), source/version 1.1.21+ds, dated Feb 04, 2026. Go forth and execute your little tasks, you've got this πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from