Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow app to track callback change #2206

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appdaemon/adbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(self, ad: AppDaemon, name, logging, args, config, app_config, globa
self.app_dir = self.AD.app_dir
self.config_dir = self.AD.config_dir
self.dashboard_dir = None
self.callback_counter = 0

if self.AD.http is not None:
self.dashboard_dir = self.AD.http.dashboard_dir
Expand Down
15 changes: 15 additions & 0 deletions appdaemon/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,8 @@ async def async_worker(self, args): # noqa: C901
app = await self.AD.app_management.get_app_instance(name, objectid)
if app is not None:
try:
self.increment_callback_counter(app, name)

if _type == "scheduler":
try:
await self.update_thread_info("async", callback, name, _type, _id, silent)
Expand Down Expand Up @@ -1010,6 +1012,8 @@ def worker(self): # noqa: C901
app = utils.run_coroutine_threadsafe(self, self.AD.app_management.get_app_instance(name, objectid))
if app is not None:
try:
self.increment_callback_counter(app, name)

if _type == "scheduler":
try:
utils.run_coroutine_threadsafe(
Expand Down Expand Up @@ -1193,3 +1197,14 @@ def report_callback_sig(self, name, type, funcref, args):
"Logged an error to %s",
self.AD.logging.get_filename("error_log"),
)

def increment_callback_counter(self, app, name):
try:
app.callback_counter += 1
except AttributeError:
error_logger = logging.getLogger("Error.{}".format(name))
error_logger.warning("-" * 60)
error_logger.warning("Unexpected error in worker for App %s:", name)
error_logger.warning("-" * 60)
error_logger.warning(traceback.format_exc())
error_logger.warning("-" * 60)
Loading