| 270 | } |
| 271 | |
| 272 | static struct command_result *clean_finished(struct clean_info *cinfo) |
| 273 | { |
| 274 | struct subsystem_and_variant sv = first_sv(); |
| 275 | do { |
| 276 | size_t num_cleaned = get_per_variant(cinfo, &sv)->num_cleaned; |
| 277 | |
| 278 | if (!num_cleaned) |
| 279 | continue; |
| 280 | |
| 281 | plugin_log(plugin, LOG_DBG, "cleaned %zu from %s", |
| 282 | num_cleaned, subsystem_to_str(&sv)); |
| 283 | *total_cleaned(&sv) += num_cleaned; |
| 284 | jsonrpc_set_datastore_string(cinfo->cmd, |
| 285 | datastore_path(tmpctx, &sv, "num"), |
| 286 | tal_fmt(tmpctx, "%"PRIu64, |
| 287 | *total_cleaned(&sv)), |
| 288 | "create-or-replace", NULL, NULL, NULL); |
| 289 | } while (next_sv(&sv)); |
| 290 | |
| 291 | /* autoclean-once? */ |
| 292 | if (cinfo != timer_cinfo) { |
| 293 | struct json_stream *response = jsonrpc_stream_success(cinfo->cmd); |
| 294 | |
| 295 | json_object_start(response, "autoclean"); |
| 296 | |
| 297 | sv = first_sv(); |
| 298 | do { |
| 299 | const struct per_variant *pv = get_per_variant(cinfo, &sv); |
| 300 | if (pv->age == 0) |
| 301 | continue; |
| 302 | json_object_start(response, subsystem_to_str(&sv)); |
| 303 | json_add_u64(response, "cleaned", pv->num_cleaned); |
| 304 | json_add_u64(response, "uncleaned", |
| 305 | get_per_subsystem(cinfo, &sv)->num_uncleaned); |
| 306 | json_object_end(response); |
| 307 | } while (next_sv(&sv)); |
| 308 | json_object_end(response); |
| 309 | return command_finished(cinfo->cmd, response); |
| 310 | } else { /* timer */ |
| 311 | plugin_log(plugin, LOG_DBG, "setting next timer"); |
| 312 | cleantimer = global_timer(plugin, |
| 313 | time_from_sec(cycle_seconds), |
| 314 | do_clean_timer, NULL); |
| 315 | return timer_complete(cinfo->cmd); |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | static struct command_result *do_clean_after_sleep(struct command *timer_cmd, |
| 320 | struct clean_info *cinfo) |
no test coverage detected