save work status

This commit is contained in:
Rongsong Shen 2025-12-10 17:24:43 +08:00
parent 89fc15b926
commit 123b656dcf
5 changed files with 93 additions and 54 deletions

View file

@ -56,30 +56,6 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state)
static struct argp argp = { options, parse_opt, args_doc, doc };
static char* verbose_to_loglevel(int verbose)
{
char* loglevel = "info";
switch (verbose) {
case 1:
loglevel = "debug";
break;
case 2:
loglevel = "debug2";
break;
case 3:
loglevel = "debug3";
break;
default:
if (verbose > 3) {
loglevel = "debug3";
}
break;
}
return loglevel;
}
int main(int argc, char* argv[])
{
struct arguments arguments;

View file

@ -232,30 +232,6 @@ static error_t parse_opt(int key, char* arg, struct argp_state* state)
static struct argp argp = { options, parse_opt, args_doc, doc };
static char* verbose_to_loglevel(int verbose)
{
char* loglevel = "info";
switch (verbose) {
case 1:
loglevel = "debug";
break;
case 2:
loglevel = "debug2";
break;
case 3:
loglevel = "debug3";
break;
default:
if (verbose > 3) {
loglevel = "debug3";
}
break;
}
return loglevel;
}
void sigbreak(int signo) { break_out = 1; }
static char* get_setting(char* key)

View file

@ -108,6 +108,7 @@ extern int get_myname(char*, size_t);
extern int mylog_init(char*, char*, int, int);
extern void mylog_fini(void);
extern int mylog_setlevel(char*);
extern char* verbose_to_loglevel(int);
extern void set_error(char*, char*, int, int);
extern ectx_t* get_ectx(void);
extern int xce_vprintf(const char*, va_list);

View file

@ -267,6 +267,30 @@ int mylog_init(char* logfile, char* loglvl, int max_log_size, int max_log_count)
return rc;
}
char* verbose_to_loglevel(int verbose)
{
char* loglevel = "info";
switch (verbose) {
case 1:
loglevel = "debug";
break;
case 2:
loglevel = "debug2";
break;
case 3:
loglevel = "debug3";
break;
default:
if (verbose > 3) {
loglevel = "debug3";
}
break;
}
return loglevel;
}
int mylog_setlevel(char* level) { return tlog_setlevel(name_to_level(level)); }
void mylog_fini() { tlog_exit(); }

View file

@ -9,7 +9,46 @@
#include "scheduler.h"
extern int scheduler_req_handler(xce_request_t *);
#include "utils.h"
extern int scheduler_req_handler(xce_request_t*);
static char doc[] = "xce_scheduler";
static char args_doc[] = "";
const char* argp_program_version
= MK_VERSION("xce v0.0.0.1-", STR(VERSION_COMMIT_ID));
const char* argp_program_bug_address = BUG_EMAIL;
struct arguments {
char* logfile;
int verbose;
};
static struct argp_option options[] = {
{ "logfile", 'l', "FILE", 0, "The full path of log file" },
{ "verbose", 'v', 0, 0, "Produce verbose log" },
{ 0 }
};
static error_t parse_opt(int key, char* arg, struct argp_state* state)
{
struct arguments* arguments = state->input;
switch (key) {
case 'l':
arguments->logfile = arg;
break;
case 'v':
arguments->verbose++;
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
static struct argp argp = { options, parse_opt, args_doc, doc };
static int init_config(xce_client_config_t* config)
{
@ -25,12 +64,12 @@ static int init_config(xce_client_config_t* config)
static int scheduler_init(xcecli_ctx_t* ctx, xce_client_config_t* config)
{
int rc = 0;
rc = xcecli_ctx_init(ctx, config);
if ( rc < 0 ) {
if (rc < 0) {
return rc;
}
xcecli_set_handler(*ctx, scheduler_req_handler);
rc = xcecli_start(*ctx);
if (rc < 0) {
@ -41,25 +80,48 @@ static int scheduler_init(xcecli_ctx_t* ctx, xce_client_config_t* config)
if (rc < 0) {
return rc;
}
return 0;
}
static void scheduler_fini(xcecli_ctx_t* ctx) { return ; }
static void scheduler_fini(xcecli_ctx_t* ctx) { return; }
int main(int argc, char* argv[])
{
struct arguments arguments;
char* logfile = "/tmp/xce_scheduler.log";
char* loglevel = "info";
int logsize = 64 * 1024 * 1024;
int logcount = 10;
xcecli_ctx_t ctx;
xce_client_config_t config;
memset(&arguments, 0x0, sizeof(arguments));
argp_parse(&argp, argc, argv, 0, 0, &arguments);
if (arguments.logfile != NULL) {
logfile = arguments.logfile;
}
if (arguments.verbose != 0) {
loglevel = verbose_to_loglevel(arguments.verbose);
}
mylog_init(logfile, loglevel, logsize, logcount);
init_config(&config);
scheduler_init(&ctx, &config);
INFO("xce scheduler is running");
while (1) {
sleep(1);
}
scheduler_fini(&ctx);
INFO("xce scheduler has been shutdown");
return 0;
}