/* * 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 #include #include #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), "%s", last_status); else buf[0] = '\0'; 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; }