Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 7014:298bfc768889
mod_admin_telnet: Make timer:info command more robust
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 23 Dec 2015 11:42:14 +0100 |
parent | 6988:329d5fb8a9d3 |
child | 7036:f26debcae34e |
comparison
equal
deleted
inserted
replaced
7013:f387fae9fb31 | 7014:298bfc768889 |
---|---|
337 end | 337 end |
338 | 338 |
339 def_env.timer = {}; | 339 def_env.timer = {}; |
340 | 340 |
341 function def_env.timer:info() | 341 function def_env.timer:info() |
342 local socket = require "socket"; | |
342 local print = self.session.print; | 343 local print = self.session.print; |
343 local add_task = require"util.timer".add_task; | 344 local add_task = require"util.timer".add_task; |
344 local h, params = add_task.h, add_task.params; | 345 local h, params = add_task.h, add_task.params; |
345 print("-- util.timer"); | 346 if h then |
346 for i, id in ipairs(h.ids) do | 347 print("-- util.timer"); |
347 if not params[id] then | 348 for i, id in ipairs(h.ids) do |
348 print(os.date("%F %T", h.priorities[i]), h.items[id]); | 349 if not params[id] then |
349 elseif not params[id].callback then | 350 print(os.date("%F %T", h.priorities[i]), h.items[id]); |
350 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id])); | 351 elseif not params[id].callback then |
351 else | 352 print(os.date("%F %T", h.priorities[i]), h.items[id], unpack(params[id])); |
352 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id])); | 353 else |
354 print(os.date("%F %T", h.priorities[i]), params[id].callback, unpack(params[id])); | |
355 end | |
353 end | 356 end |
354 end | 357 end |
355 if server.event_base then | 358 if server.event_base then |
356 local count = 0; | 359 local count = 0; |
357 for k, v in pairs(debug.getregistry()) do | 360 for k, v in pairs(debug.getregistry()) do |
358 if type(v) == "function" and v.callback == add_task._on_timer then | 361 if type(v) == "function" and v.callback and v.callback == add_task._on_timer then |
359 count = count + 1; | 362 count = count + 1; |
360 end | 363 end |
361 end | 364 end |
362 print(count .. " libevent callbacks"); | 365 print(count .. " libevent callbacks"); |
363 end | 366 end |
364 local next_time = h:peek(); | 367 if h then |
365 if next_time then | 368 local next_time = h:peek(); |
366 return true, os.date("Next event at %F %T", next_time); | 369 if next_time then |
370 return true, os.date("Next event at %F %T (in %%.6fs)", next_time):format(next_time - socket.gettime()); | |
371 end | |
367 end | 372 end |
368 return true; | 373 return true; |
369 end | 374 end |
370 | 375 |
371 def_env.module = {}; | 376 def_env.module = {}; |