Skip to content

Commit

Permalink
Add scheduler event loop warning
Browse files Browse the repository at this point in the history
  • Loading branch information
acockburn committed Aug 22, 2017
1 parent b8a2991 commit 205e522
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion appdaemon/appdaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def do_every(period, f):
def do_every_second(utc):

try:

start_time = datetime.datetime.now().timestamp()
now = datetime.datetime.fromtimestamp(utc)
conf.now = utc

Expand Down Expand Up @@ -463,6 +463,14 @@ def do_every_second(utc):
if v == {}:
del conf.schedule[k]

end_time = datetime.datetime.now().timestamp()

loop_duration = (int((end_time - start_time)*1000) / 1000) * 1000
ha.log(conf.logger, "DEBUG", "Main loop compute time: {}ms".format(loop_duration))

if loop_duration > 900:
ha.log(conf.logger, "WARNING", "Excessive time spent in scheduler loop: {}ms".format(loop_duration))

return utc

except:
Expand Down
1 change: 0 additions & 1 deletion appdaemon/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self, config_dir, logger, **kwargs):
# Set a start time
#
self.start_time = datetime.datetime.now()
print(self.dashboard_dir)

def __timeit(func):
@functools.wraps(func)
Expand Down
3 changes: 2 additions & 1 deletion docs/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Change Log

**Features**

None
- Refactor of dashboard code in preparation for HASS integration
- Addition of check to highlight excessive time in scheduler loop

**Fixes**

Expand Down

0 comments on commit 205e522

Please sign in to comment.