merge job rusage and pending reason support

This commit is contained in:
Rongsong Shen 2025-12-16 14:36:28 +08:00
parent 30824ae5ea
commit cb0c7fe9e7
82 changed files with 4280 additions and 2561 deletions

View file

@ -27,6 +27,48 @@ int xce_hello(xce_ctx_t* ctx, char* msg)
return status;
}
int xce_nop(xce_ctx_t* ctx)
{
int rc;
if (ctx == NULL) {
return -EINVAL;
}
if (ctx->state != XCE_CTX_RUN) {
return -EINVAL;
}
rc = xce_nop_req(ctx->ep);
/* no need to wait reply, just as heartbeat */
return rc;
}
int xce_heartbeat(xce_ctx_t* ctx, int hb_interval)
{
time_t now;
if (ctx == NULL) {
return -EINVAL;
}
if (ctx->state != XCE_CTX_RUN) {
return -EINVAL;
}
if (ctx->ep == NULL) {
return -EINVAL;
}
now = time(NULL);
if (now - ctx->ep->ts_last_out < hb_interval) {
return 0;
}
return xce_nop(ctx);
}
int xce_shutdown(xce_ctx_t* ctx)
{
int rc;
@ -45,13 +87,11 @@ int xce_shutdown(xce_ctx_t* ctx)
return rc;
}
int xce_get(xce_ctx_t* ctx, int table, void*** data)
int xce_get_with_condition(xce_ctx_t* ctx, xce_get_t* get, void*** data)
{
int rc;
int status;
xce_match_t condition = { .type = MatchCondition_condition_matchall };
xce_get_t get = { .table = table, .condition = &condition };
dataset_t getreply = { .table = table, .nrows = 0, .rows = NULL };
int rc;
int status;
dataset_t getreply;
if (ctx == NULL) {
return -EINVAL;
@ -61,8 +101,12 @@ int xce_get(xce_ctx_t* ctx, int table, void*** data)
return -EINVAL;
}
if ((get == NULL) || (data == NULL)) {
return -EINVAL;
}
ctx->reply.u.get = &getreply;
rc = xce_get_req(ctx->ep, &get);
rc = xce_get_req(ctx->ep, get);
if (rc < 0) {
return rc;
}
@ -84,6 +128,21 @@ int xce_get(xce_ctx_t* ctx, int table, void*** data)
return rc;
}
int xce_get(xce_ctx_t* ctx, int table, void*** data)
{
/* clang-format off */
xce_match_t condition = {
.type = MatchCondition_condition_matchall
};
xce_get_t get = {
.table = table,
.condition = &condition
};
/* clang-format on */
return xce_get_with_condition(ctx, &get, data);
}
int xce_reslist(xce_ctx_t* ctx, xce_resource_t*** res)
{
int table = Data_data_resources;
@ -524,3 +583,88 @@ int xce_runtask(xce_ctx_t* ctx, xce_taskrun_t* runinfo)
return status;
}
int xce_set_pend_reason(xce_ctx_t* ctx, xce_preason_set_t* reasons)
{
int rc;
int status;
if (ctx == NULL) {
return -EINVAL;
}
if (ctx->state != XCE_CTX_RUN) {
return -EINVAL;
}
rc = xce_set_pend_reason_req(ctx->ep, reasons);
if (rc < 0) {
return rc;
}
rc = cbuf_get(&(ctx->wbuf), &status);
if (rc < 0) {
return rc;
}
return status;
}
int xce_clear_reason(xce_ctx_t* ctx, xce_clear_reason_t* reasons)
{
int rc;
int status;
if (ctx == NULL) {
return -EINVAL;
}
if (ctx->state != XCE_CTX_RUN) {
return -EINVAL;
}
rc = xce_clear_reason_req(ctx->ep, reasons);
if (rc < 0) {
return rc;
}
rc = cbuf_get(&(ctx->wbuf), &status);
if (rc < 0) {
return rc;
}
return status;
}
int xce_jobinfo(xce_ctx_t* ctx, uint64_t jobid, xce_job_t** job)
{
/* clang-format off */
xce_match_t condition = {
.type = MatchCondition_condition_matchjid,
.condition = {
.jobid = jobid
}
};
xce_get_t get = {
.table = Data_data_jobs,
.condition = &condition
};
/* clang-format on */
int rc;
xce_job_t** jobs;
if ((ctx == NULL) || (job == NULL)) {
return -EINVAL;
}
rc = xce_get_with_condition(ctx, &get, (void***)&jobs);
if (rc <= 0) {
return rc;
}
*job = jobs[0];
FREEUP(jobs);
return 1;
}