37 #include "clientpipe.h" 44 static const char *module_str =
"time_leap_cmd";
51 " --time <time> aka -t \n" 60 "*WARNING* time leap is a debugging/testing tool, it should NEVER be used\n" 61 "in production! Without arguments the daemon inspects the first task in the\n" 62 "schedule and sets its internal time to the time of the task. This allows for\n" 63 "a quick replay of a test scenario. With the --time or -t switch the daemon\n" 64 "sets its time to the argument given as: \"YYYY-MM-DD-HH:MM:SS\"." 67 "time leap to this exact time\n" 68 "attach Perform 1 task and stay attached, use only when workerthreads=0\n\n" 73 handles(
const char *cmd, ssize_t n)
79 run(
int sockfd,
engine_type* engine,
const char *cmd, ssize_t n,
82 struct tm strtime_struct;
84 char buf[ODS_SE_MAXLINE];
85 time_t now = time_now();
86 const char *time = NULL;
91 int argc, attach, cont;
93 (void)n; (void)dbconn;
97 strncpy(buf, cmd,
sizeof(buf));
98 buf[
sizeof(buf)-1] =
'\0';
99 argc = ods_str_explode(buf, NARGV, argv);
101 ods_log_error_and_printf(sockfd, module_str,
"too many arguments");
104 (void)ods_find_arg_and_param(&argc, argv,
"time",
"t", &time);
106 if (strptime(time,
"%Y-%m-%d-%H:%M:%S", &tm)) {
108 time_leap = mktime(&tm);
109 client_printf(sockfd,
110 "Using %s parameter value as time to leap to\n", time);
112 client_printf_err(sockfd,
113 "Time leap: Error - could not convert '%s' to a time. " 114 "Format is YYYY-MM-DD-HH:MM:SS \n", time);
118 attach = ods_find_arg(&argc,argv,
"attach",
"a") != -1;
121 ods_log_error_and_printf(sockfd, module_str,
"unknown arguments");
125 ods_log_assert(engine);
127 client_printf(sockfd,
"There are no tasks scheduled.\n");
133 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&now, &strtime_struct));
134 client_printf(sockfd,
135 "There are %i tasks scheduled.\nIt is now %s (%ld seconds since epoch)\n",
141 if (time_leap < 0)
break;
142 if (now > time_leap) {
146 set_time_now(time_leap);
147 strftime(strtime,
sizeof(strtime),
"%c", localtime_r(&time_leap, &strtime_struct));
149 client_printf(sockfd,
"Leaping to time %s (%ld seconds since epoch)\n",
150 (strtime[0]?strtime:
"(null)"), (
long)time_leap);
151 ods_log_info(
"Time leap: Leaping to time %s\n", strtime);
154 client_printf(sockfd,
"Waking up workers\n");
160 client_printf(sockfd,
"[timeleap] attaching to job %s\n",
task_what2str(task->
what));
167 newtask->dbconn = NULL;
void engine_wakeup_workers(engine_type *engine)
void ods_log_debug(const char *format,...)
task_type * schedule_pop_first_task(schedule_type *schedule)
void ods_log_info(const char *format,...)
int(* run)(int sockfd, struct engine_struct *engine, const char *cmd, ssize_t n, db_connection_t *dbconn)
ods_status schedule_task(schedule_type *schedule, task_type *task)
void(* usage)(int sockfd)
time_t schedule_time_first(schedule_type *schedule)
task_type * task_perform(task_type *task)
const char * task_what2str(int what)
struct cmd_func_block * time_leap_funcblock(void)
void hsm_key_factory_generate_all(engine_type *engine, const db_connection_t *connection, time_t duration)
int(* handles)(const char *cmd, ssize_t n)
size_t schedule_taskcount(schedule_type *schedule)