env=NAME=VALUE on a delegate line (repeatable) is set in the child right before exec and beats what the parent exported, so two delegates can run the same cli with two accounts. Remotely it goes in front as `env 'NAME=VALUE'`, quoted like the rest. cli_env = NAME=VALUE does the same for the main cli transport. A bad name is an error with the line. Also in this commit, the work in progress from the tree: swarm and provider state, the provider/scheduler/planner/tmux plugins, the ui test, whose tmux session name is now per run so parallel runs do not collide. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
1.8 KiB
C
88 lines
1.8 KiB
C
/*
|
|
* splinter -- delegation scheduler (auto-retry due jobs).
|
|
*
|
|
* Ticks periodically and retries one due durable delegation job
|
|
* (waiting_quota / waiting_poll / queued with run_after/next_poll_at reached).
|
|
* This enables "quota back in N days -> auto-scheduled" when combined with
|
|
* provider preflight/account and durable job records.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
|
|
#include "splinter.h"
|
|
#include "splinter_plugin.h"
|
|
|
|
static struct sp_host *host_ref;
|
|
static char last_status[256];
|
|
static long last_run;
|
|
|
|
static void
|
|
publish(struct sp_host *h)
|
|
{
|
|
char buf[320];
|
|
if (!h) return;
|
|
if (last_status[0])
|
|
snprintf(buf, sizeof(buf), "sched: %s", last_status);
|
|
else
|
|
snprintf(buf, sizeof(buf), "sched: idle");
|
|
sp_host_widget_text(h, "scheduler", buf);
|
|
}
|
|
|
|
static int
|
|
sched_tick(struct sp_host *h, const char *name, void *ctx)
|
|
{
|
|
struct sp_buf out;
|
|
long now = (long)time(NULL);
|
|
int rc;
|
|
(void)name; (void)ctx;
|
|
if (now - last_run < 15)
|
|
return 0;
|
|
last_run = now;
|
|
if (sp_buf_init(&out) != 0)
|
|
return 0;
|
|
rc = sp_delegate_tick(&out);
|
|
if (out.p && strstr(out.p, "none due") == NULL) {
|
|
snprintf(last_status, sizeof(last_status), "%.200s",
|
|
out.p ? out.p : (rc == 0 ? "ok" : "err"));
|
|
} else if (last_status[0] == '\0') {
|
|
snprintf(last_status, sizeof(last_status), "idle");
|
|
}
|
|
sp_buf_free(&out);
|
|
publish(h ? h : host_ref);
|
|
return 0;
|
|
}
|
|
|
|
static const struct sp_widget widget = {
|
|
"scheduler",
|
|
sched_tick,
|
|
NULL,
|
|
NULL,
|
|
30000 /* 30s */
|
|
};
|
|
|
|
static int
|
|
scheduler_init(struct sp_host *h)
|
|
{
|
|
host_ref = h;
|
|
snprintf(last_status, sizeof(last_status), "idle");
|
|
(void)sp_host_add_widget(h, &widget);
|
|
publish(h);
|
|
return 0;
|
|
}
|
|
|
|
static const struct sp_plugin plugin = {
|
|
SP_PLUGIN_ABI,
|
|
"scheduler",
|
|
"0.1",
|
|
scheduler_init,
|
|
NULL,
|
|
NULL
|
|
};
|
|
|
|
const struct sp_plugin *
|
|
sp_plugin_describe(void)
|
|
{
|
|
return &plugin;
|
|
}
|