0

I did check the example reverse_client_cb with the reverse_worker as a worker. The worker is getting called and executed but not a single callback ( complete,fail,etc) is getting called in the client.

Below is a sample worker and client that I wrote to check the same, but, same problem. Is there any configuration that's need to be done in gearman or in the way the worker and clients are executed?

sampleworker.cc

void* myfunc(gearman_job_st *job, void *data,size_t *size,gearman_return_t *ret)
{
    printf("\nmyfunc called\n");

    *ret=GEARMAN_SUCCESS;
    char *result=(char*)calloc(30,sizeof(char));
    strcpy(result,"work completed");
    *size=30;
    return result;
}

int main(int args,char* argv[])
{
   gearman_worker_st worker;

   gearman_worker_create(&worker);
   gearman_worker_add_server(&worker,"localhost",0);

   gearman_return_t ret =     gearman_worker_add_function(&worker,"sample",0,myfunc,NULL);

   while(1) gearman_worker_work(&worker);

   gearman_worker_free(&worker);
   return 0;
}

sampleclient.cc

static gearman_return_t complete(gearman_task_st *task)
{
     printf("Completed: %s %.*s\n", gearman_task_job_handle(task),
     (int)gearman_task_data_size(task), (char *)gearman_task_data(task));
     return GEARMAN_SUCCESS;
}

static gearman_return_t fail(gearman_task_st *task)
{
    printf("Failed: %s\n", gearman_task_job_handle(task));
    return GEARMAN_SUCCESS;
}

 int main(int args,char* argv[])
{
        gearman_client_st client;
    gearman_return_t ret;

    gearman_client_create(&client);
    gearman_client_add_server(&client,"localhost",0);

    gearman_task_st task,*task2;
    gearman_client_add_task(&client,&task,NULL,"sample",NULL,argv[1],(size_t)strlen(argv[1]),&ret);

    gearman_client_set_complete_fn(&client, &complete);
    gearman_client_set_fail_fn(&client, &fail);

    gearman_client_run_tasks(&client);  

    gearman_client_free(&client);
    return 0;
  }

usage

./sampleworker
./sampleclient Hello

"myfunc called" getting printed and the client is also waiting till the worker completes the job. But nothing is printed from complete or fail functions

venu
  • 1
  • 1

2 Answers2

0

got it.

I removed the following libs which was installed and now I'm getting all the callbacks.

libgearman-client-async-perl - Asynchronous client for gearman distributed job system

libgearman-client-perl - Client for gearman distributed job system.

Community
  • 1
  • 1
venu
  • 1
  • 1
0

in my opinion. your made some mistake in function invoking sequence.

gearman_client_set_complete_fn(&client, &complete);
gearman_client_set_fail_fn(&client, &fail);

// the function must be called after set_complete_fn

gearman_client_add_task 
gearman_client_run_tasks(&client);