Skip to content

Commit

Permalink
Avoid other cases of throwing error due to unregistered isntance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding committed Jul 8, 2022
1 parent 9f2c9d6 commit af3604b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion awx/main/analytics/subsystem_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ def __init__(self, auto_pipe_execute=False, instance_name=None):
elif settings.IS_TESTING():
self.instance_name = "awx_testing"
else:
self.instance_name = Instance.objects.me().hostname
try:
self.instance_name = Instance.objects.me().hostname
except Exception as e:
self.instance_name = settings.CLUSTER_HOST_ID
logger.info(f'Instance {self.instance_name} seems to be unregistered, error: {e}')

# metric name, help_text
METRICSLIST = [
Expand Down
6 changes: 5 additions & 1 deletion awx/main/dispatch/reaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def startup_reaping():
If this particular instance is starting, then we know that any running jobs are invalid
so we will reap those jobs as a special action here
"""
me = Instance.objects.me()
try:
me = Instance.objects.me()
except RuntimeError as e:
logger.warning(f'Local instance is not registered, not running startup reaper: {e}')
return
jobs = UnifiedJob.objects.filter(status='running', controller_node=me.hostname)
job_ids = []
for j in jobs:
Expand Down
3 changes: 1 addition & 2 deletions awx/main/management/commands/run_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.core.management.base import BaseCommand
from django.db import connection as django_connection

from awx.main.dispatch import get_local_queuename, reaper
from awx.main.dispatch import get_local_queuename
from awx.main.dispatch.control import Control
from awx.main.dispatch.pool import AutoscalePool
from awx.main.dispatch.worker import AWXConsumerPG, TaskWorker
Expand Down Expand Up @@ -53,7 +53,6 @@ def handle(self, *arg, **options):
# (like the node heartbeat)
periodic.run_continuously()

reaper.startup_reaping()
consumer = None

try:
Expand Down
1 change: 1 addition & 0 deletions awx/main/tasks/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def dispatch_startup():
#
apply_cluster_membership_policies()
cluster_node_heartbeat()
reaper.startup_reaping()
m = Metrics()
m.reset_values()

Expand Down

0 comments on commit af3604b

Please sign in to comment.