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
|
@api.model
|
||||||
def _cron_health_check(self):
|
def _cron_health_check(self):
|
||||||
"""Ping all connected instances and flag unreachable ones."""
|
"""Ping all connected instances. Only log warnings — never change state.
|
||||||
instances = self.search([('state', '!=', 'draft')])
|
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:
|
for instance in instances:
|
||||||
try:
|
try:
|
||||||
client = instance._get_client()
|
client = instance._get_client()
|
||||||
success, _info = client.test_connection()
|
success, _info = client.test_connection()
|
||||||
if success:
|
if success:
|
||||||
if instance.state == 'error':
|
_logger.info("Health check OK for %s", instance.name)
|
||||||
instance.state = 'connected'
|
|
||||||
instance.message_post(body="Health check passed — connection restored.")
|
|
||||||
else:
|
else:
|
||||||
instance.state = 'error'
|
_logger.warning("Health check failed for %s — store may be unreachable", instance.name)
|
||||||
instance.message_post(body="Health check failed — store unreachable.")
|
|
||||||
instance._notify_failure('health', 'Store unreachable during health check.')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
instance.state = 'error'
|
_logger.warning("Health check error for %s: %s", instance.name, e)
|
||||||
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)
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# Order Sync (Task 20)
|
# Order Sync (Task 20)
|
||||||
|
|||||||
Reference in New Issue
Block a user