38 #include "scheduler/schedule.h"
39 #include "cmdhandler.h"
42 #include "clientpipe.h"
43 #include "clientpipe.h"
46 #include "scheduler/task.h"
48 static 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."
69 run(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
71 struct tm strtime_struct;
73 char* taskdescription;
78 ldns_rbnode_t* node = LDNS_RBTREE_NULL;
79 task_type* task = NULL;
84 ods_log_debug(
"[%s] list tasks command", module_str);
86 ods_log_assert(engine);
88 client_printf(sockfd,
"There are no tasks scheduled.\n");
92 schedule_info(engine->
taskq, &nextFireTime, &num_waiting, &count);
94 client_printf(sockfd,
"All worker threads idle.\n");
98 client_printf(sockfd,
"There %s %i %s scheduled.\n",
99 (count==1)?
"is":
"are", (
int) count, (count==1)?
"task":
"tasks");
101 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&now, &strtime_struct));
102 client_printf(sockfd,
"It is now %s (%ld seconds since epoch)\n", (strtime[0]?strtime:
"(null)"), (
long)now);
103 if (nextFireTime > now) {
104 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&nextFireTime, &strtime_struct));
105 client_printf(sockfd,
"Next task scheduled %s (%ld seconds since epoch)\n", strtime, (
long)nextFireTime);
106 }
else if (nextFireTime >= 0) {
107 client_printf(sockfd,
"Next task scheduled immediately\n");
111 pthread_mutex_lock(&engine->
taskq->schedule_lock);
112 node = ldns_rbtree_first(engine->
taskq->tasks);
113 while (node && node != LDNS_RBTREE_NULL) {
114 task = (task_type*) node->data;
115 taskdescription = schedule_describetask(task);
116 client_printf(sockfd,
"%s", taskdescription);
117 free(taskdescription);
118 node = ldns_rbtree_next(node);
120 pthread_mutex_unlock(&engine->
taskq->schedule_lock);
125 "queue", &usage, &help, NULL, &run
129 usage_flush(
int sockfd)
131 client_printf(sockfd,
137 help_flush(
int sockfd)
139 client_printf(sockfd,
140 "Execute all scheduled tasks immediately.\n\n");
144 run_flush(
int sockfd, cmdhandler_ctx_type* context,
const char *cmd)
148 ods_log_debug(
"[%s] flush tasks command", module_str);
149 ods_log_assert(engine);
150 ods_log_assert(engine->
taskq);
152 schedule_flush(engine->
taskq);
154 client_printf(sockfd,
"All tasks scheduled immediately.\n");
155 ods_log_verbose(
"[cmdhandler] all tasks scheduled immediately");
160 "flush", &usage_flush, &help_flush, NULL, &run_flush