From d0fe0ed796425cca4dea6431f36f6820c0c98e42 Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Fri, 31 May 2024 09:29:40 -0400 Subject: [PATCH] Add check_instance_ready management command (#15238) - throw exception and return 1 if instance not ready - return 0 if ready --- awx/main/management/commands/check_instance_ready.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 awx/main/management/commands/check_instance_ready.py diff --git a/awx/main/management/commands/check_instance_ready.py b/awx/main/management/commands/check_instance_ready.py new file mode 100644 index 0000000000..833870d8db --- /dev/null +++ b/awx/main/management/commands/check_instance_ready.py @@ -0,0 +1,12 @@ +from django.core.management.base import BaseCommand, CommandError +from awx.main.models.ha import Instance + + +class Command(BaseCommand): + help = 'Check if the task manager instance is ready throw error if not ready, can be use as readiness probe for k8s.' + + def handle(self, *args, **options): + if Instance.objects.me().node_state != Instance.States.READY: + raise CommandError('Instance is not ready') # so that return code is not 0 + + return