38#include "scheduler/schedule.h"
39#include "cmdhandler.h"
42#include "clientpipe.h"
43#include "longgetopt.h"
46#include "scheduler/task.h"
48static const char *module_str =
"queue_cmd";
62 "queue shows all scheduled tasks with their time of earliest executions,\n"
63 "as well as all tasks currently being processed."
69run(cmdhandler_ctx_type* context,
int argc,
char* argv[])
71 int sockfd = context->sockfd;
72 struct tm strtime_struct;
74 char* taskdescription;
78 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
79 task_type* task = NULL;
83 ods_log_debug(
"[%s] list tasks command", module_str);
85 ods_log_assert(engine);
87 client_printf(sockfd,
"There are no tasks scheduled.\n");
91 schedule_info(engine->
taskq, &nextFireTime, &num_waiting, &count);
93 client_printf(sockfd,
"All worker threads idle.\n");
97 client_printf(sockfd,
"There %s %i %s scheduled.\n",
98 (count==1)?
"is":
"are", (
int) count, (count==1)?
"task":
"tasks");
100 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&now, &strtime_struct));
101 client_printf(sockfd,
"It is now %s (%ld seconds since epoch)\n", (strtime[0]?strtime:
"(null)"), (
long)now);
102 if (nextFireTime > now) {
103 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&nextFireTime, &strtime_struct));
104 client_printf(sockfd,
"Next task scheduled %s (%ld seconds since epoch)\n", strtime, (
long)nextFireTime);
105 }
else if (nextFireTime >= 0) {
106 client_printf(sockfd,
"Next task scheduled immediately\n");
110 pthread_mutex_lock(&engine->
taskq->schedule_lock);
111 node = ldns_rbtree_first(engine->
taskq->tasks);
112 while (node && node != LDNS_RBTREE_NULL) {
113 task = (task_type*) node->data;
114 taskdescription = schedule_describetask(task);
115 client_printf(sockfd,
"%s", taskdescription);
116 free(taskdescription);
117 node = ldns_rbtree_next(node);
119 pthread_mutex_unlock(&engine->
taskq->schedule_lock);
124 "queue", &usage, &help, NULL, NULL, &run, NULL
128usage_flush(
int sockfd)
130 client_printf(sockfd,
136help_flush(
int sockfd)
138 client_printf(sockfd,
139 "Execute all scheduled tasks immediately.\n\n");
143run_flush(cmdhandler_ctx_type* context,
int argc,
char* argv[])
145 int sockfd = context->sockfd;
147 ods_log_debug(
"[%s] flush tasks command", module_str);
148 ods_log_assert(engine);
149 ods_log_assert(engine->
taskq);
151 schedule_flush(engine->
taskq);
153 client_printf(sockfd,
"All tasks scheduled immediately.\n");
154 ods_log_verbose(
"[cmdhandler] all tasks scheduled immediately");
159 "flush", &usage_flush, &help_flush, NULL, NULL, &run_flush, NULL
engine_type * getglobalcontext(cmdhandler_ctx_type *context)
struct cmd_func_block queue_funcblock
struct cmd_func_block flush_funcblock
engineconfig_type * config