Thursday, April 7, 2011

Additions to the Gearman API

There are a number of new things which are coming to the germane API that I thought I would blog about (and before anyone asks, all of the old API is available as well).


Here is an example of usage:


 gearman_function_st *function= gearman_function_create(gearman_literal_param(WORKER_FUNCTION_NAME));


Functions are now a type. There is a lot being done to make functions more powerful by having context and meaning within the server. This begins to expose some of that. gearman_function_t itself being a type allows us to add characteristics to the function. Functions can also now be written to use any valid UTF-8 as a name, which was something that was not really possible in the past (it worked in almost all cases). 


  gearman_workload_t workload= gearman_workload_make(gearman_literal_param(“test load”));


  gearman_workload_set_background(&workload, true);


This is an example of generating a workload and will be passed into the server. The workload type is very lightweight, it essentially wraps the characteristics of the work. It does zero memory allocation of its own when creating the type to it is simple to generate them and not be concerned about having to clean them up. Things like background, priority, scheduled time, and a few other characteristics can all be specified. Just like function it is not tied to any single client connection so it can be resent to multiple clients without worrying the lifetime of any single client.


  gearman_unique_t unique= gearman_unique_make(gearman_literal_param(“my id”));


Unique keys are also now given their own value. You can continue to have the server generate one as needed, or you can create your own.


  gearman_status_t status= gearman_client_execute(client,


                                                  function,


                                                  &unique,


                                                  &workload);


gearman_client_execute() is now the new workhorse of all methods.  By having characteristics on functions and workload we remove the need to have dozens of commands.


  if (gearman_status_is_successful(status)


{


 gearman_task_st *task= gearman_status_task(status);


}


Status types now give you information on what has occurred with a job. If appropriate, you can also have access to the task that was generated from the execution of a job. All of this is now available in the build trees for Gearman. Have fun with it!

No comments:

Post a Comment