fix: health check no longer changes instance state
The health check cron runs inside Docker which can't always reach external URLs. It was setting state to 'error' breaking fetch/sync. Now it only logs warnings — state changes only via explicit Test Connection button. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -383,25 +383,20 @@ class WooInstance(models.Model):
|
||||
|
||||
@api.model
|
||||
def _cron_health_check(self):
|
||||
"""Ping all connected instances and flag unreachable ones."""
|
||||
instances = self.search([('state', '!=', 'draft')])
|
||||
"""Ping all connected instances. Only log warnings — never change state.
|
||||
The health check runs from inside Docker which may not reach external URLs.
|
||||
State should only be changed by explicit user action (Test Connection button)."""
|
||||
instances = self.search([('state', '=', 'connected')])
|
||||
for instance in instances:
|
||||
try:
|
||||
client = instance._get_client()
|
||||
success, _info = client.test_connection()
|
||||
if success:
|
||||
if instance.state == 'error':
|
||||
instance.state = 'connected'
|
||||
instance.message_post(body="Health check passed — connection restored.")
|
||||
_logger.info("Health check OK for %s", instance.name)
|
||||
else:
|
||||
instance.state = 'error'
|
||||
instance.message_post(body="Health check failed — store unreachable.")
|
||||
instance._notify_failure('health', 'Store unreachable during health check.')
|
||||
_logger.warning("Health check failed for %s — store may be unreachable", instance.name)
|
||||
except Exception as e:
|
||||
instance.state = 'error'
|
||||
instance.message_post(body=f"Health check error: {e}")
|
||||
instance._notify_failure('health', str(e))
|
||||
_logger.error("Health check failed for %s: %s", instance.name, e)
|
||||
_logger.warning("Health check error for %s: %s", instance.name, e)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Order Sync (Task 20)
|
||||
|
||||
Reference in New Issue
Block a user