support passing args to request handle for elimination of global var

This commit is contained in:
Rongsong Shen 2025-12-11 17:07:51 +08:00
parent 79124c6e5c
commit 486b38d679
8 changed files with 120 additions and 19 deletions

View file

@ -1,3 +1,4 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -6,5 +7,97 @@
#include "xce/types.h"
#include "scheduler.h"
#include "utils.h"
int scheduler_req_handler(xce_request_t* request) { return 0; }
static int sched_handle_config(xce_conf4sched_t* config)
{
TRACE("%s...", __func__);
TRACE("my cluster name %s", config->clustername);
return 0;
}
static int sched_handle_jobpush(xce_jobs_data_t* jobs)
{
TRACE("%s...", __func__);
return 0;
}
static int sched_handle_workerpush(xce_workers_data_t* workers)
{
TRACE("%s...", __func__);
return 0;
}
static int sched_on_jobs(int njobs, xce_job_t **jobs) {
return 0;
}
static int sched_on_workers(int nworkers, xce_worker_t **workers) {
return 0;
}
static int sched_handle_dataset(dataset_t* dataset)
{
int rc = 0;
TRACE("%s table = %d", __func__, dataset->table);
switch (dataset->table) {
case Data_data_schedjobs:
rc = sched_on_jobs(dataset->nrows, (xce_job_t **)dataset->rows);
break;
case Data_data_schedworkers:
rc = sched_on_workers(dataset->nrows, (xce_worker_t **)dataset->rows);
break;
case Data_data_resources:
break;
case Data_data_resvals:
break;
}
return rc;
}
int scheduler_req_handler(xce_request_t* request)
{
int rc = 0;
switch (request->opcode) {
case OPCode_push:
switch (request->body_which) {
case Request_body_configpushmsg:
/* configuration arriving */
rc = sched_handle_config(
request->body.configpushmsg->data.conf4sched);
break;
case Request_body_pushmsg:
/* data arriving */
switch (request->body.pushmsg->table) {
case Data_data_schedjobs:
/* job arriving */
rc = sched_handle_jobpush(request->body.pushmsg->data.jobs);
break;
case Data_data_schedworkers:
/* workers arriving */
rc = sched_handle_workerpush(
request->body.pushmsg->data.workers);
break;
}
break;
case Request_body_datamsg:
rc = sched_handle_dataset(request->body.datamsg);
break;
default:
rc = -EINVAL;
break;
}
break;
default:
rc = -EINVAL;
break;
}
return rc;
}

View file

@ -11,7 +11,7 @@
#include "utils.h"
extern int scheduler_req_handler(xce_request_t*);
extern int scheduler_req_handler(xce_request_t*, void*);
static char doc[] = "xce_scheduler";
static char args_doc[] = "";
@ -70,7 +70,7 @@ static int scheduler_init(xcecli_ctx_t* ctx, xce_client_config_t* config)
return rc;
}
xcecli_set_handler(*ctx, scheduler_req_handler);
xcecli_set_handler(*ctx, scheduler_req_handler, NULL);
rc = xcecli_start(*ctx);
if (rc < 0) {
return rc;