---
name: "gearman_worker_define_function"
section: "3"
platform: "linux"
package: "gearmand"
version: "2.2.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/gearman_worker_define_function"
---

# gearman\_worker\_define\_function(3)

Gearmand Documentation, https://gearman.org/gearmand/

## NAME

gearman\_worker\_define\_function - Gearmand Documentation, https://gearman.org/gearmand/

## SYNOPSIS

\#include \<libgearman/gearman.h\>

- **type gearman\_function\_t**

  - ***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)**

  - **type gearman\_function\_fn**

  - **type gearman\_aggregator\_fn**

  Link with -lgearman

## DESCRIPTION

*gearman\_worker\_define\_function()* defines functions for a worker.

The interface is callback by design. When the server has a job for the worker, *gearman\_function\_fn* is evoked with a *gearman\_job\_st* representing the job, and the context that was defined originally when the function was defined.

Results are sent back to the client by invoking *gearman\_job\_send\_data()*.

If the client specified an reducer function, then the output of the *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 *gearman\_job\_send\_data()*.

If any errors are detected then the entire job is cancelled.  The *gearman\_aggregator\_fn* will be called when all mapped jobs have completed. The result of this function will be what is returned to the client.

The callback function needs to return one of the following errors:

**GEARMAN\_SUCCESS**

The function was successful.

*GEARMAN\_FAIL*

An error has occurred, the job we not processed, and the worker cannot continue.

*GEARMAN\_ERROR*

A transient error has occurred, like a network failure, and the job can be restarted.

If a value other then the above are returned it is converted to a *GEARMAN\_FAIL* and *gearman\_worker\_work()* returns *GEARMAN\_INVALID\_ARGUMENT*.

*gearman\_job\_send\_complete()* and *gearman\_job\_send\_fail()* cannot be used with any functions created with *gearman\_worker\_define\_function()*.

## RETURN VALUE

*gearman\_return\_t*

## HOME

To find out more information please check: *https://gearman.org/gearmand/*

## SEE ALSO

**[gearmand(8)](/gearmand/8.md)** **[libgearman(3)](/libgearman/3.md)** **[gearman\_strerror(3)](/gearman_strerror/3.md)** **gearman\_client\_error** **gearman\_client\_execute\_reduce**

## AUTHOR

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

## COPYRIGHT

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