Fix template evaluation timeouts and add retry logic
Some checks failed
Release Drafter / update_release_draft (push) Failing after 4s
Some checks failed
Release Drafter / update_release_draft (push) Failing after 4s
- Add 10 second timeout to template evaluation HTTP calls - Add retry logic that schedules retry after 30 seconds on failure - Maintains existing error handling while preventing silent failures - Fixes issue where template errors cause data to stay stale until next WebSocket event
This commit is contained in:
@@ -94,10 +94,42 @@ async function evaluateTemplate(payload) {
|
|||||||
this.logger.debug(`Evaluating template for ${payload.template}`);
|
this.logger.debug(`Evaluating template for ${payload.template}`);
|
||||||
}
|
}
|
||||||
const hass = this.connections[payload.identifier].hass;
|
const hass = this.connections[payload.identifier].hass;
|
||||||
const response = await hass.templates.render(payload.template);
|
|
||||||
|
try {
|
||||||
|
// Wrap template call with timeout
|
||||||
|
const response = await Promise.race([
|
||||||
|
hass.templates.render(payload.template),
|
||||||
|
new Promise((_, reject) =>
|
||||||
|
setTimeout(() => reject(new Error('Template evaluation timeout')), 10000)
|
||||||
|
)
|
||||||
|
]);
|
||||||
return {
|
return {
|
||||||
identifier: payload.identifier,
|
identifier: payload.identifier,
|
||||||
render: response
|
render: response
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(`Template evaluation failed: ${err.message}`);
|
||||||
|
|
||||||
|
// Schedule retry after 30 seconds
|
||||||
|
setTimeout(() => {
|
||||||
|
this.logger.info(`Retrying template evaluation for ${payload.identifier}`);
|
||||||
|
this.evaluateTemplate(payload).then((ret) => {
|
||||||
|
// Send appropriate notification based on original request type
|
||||||
|
if (payload.section !== undefined) {
|
||||||
|
this.sendSocketNotification("SECTION_DISPLAY_RENDERED", {
|
||||||
|
...ret,
|
||||||
|
section: payload.section
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.sendSocketNotification("MODULE_DISPLAY_RENDERED", ret);
|
||||||
|
}
|
||||||
|
}).catch((retryErr) => {
|
||||||
|
this.logger.error(`Template evaluation retry also failed: ${retryErr.message}`);
|
||||||
|
});
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
// Re-throw to maintain existing error handling behavior
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user