Shortcut Instance.objects.me when possible

This commit is contained in:
Alan Rominger
2022-08-18 16:01:49 -04:00
parent 03eaeac459
commit a64467c5a6
6 changed files with 29 additions and 41 deletions

View File

@@ -99,9 +99,12 @@ class InstanceManager(models.Manager):
instance or role.
"""
def my_hostname(self):
return settings.CLUSTER_HOST_ID
def me(self):
"""Return the currently active instance."""
node = self.filter(hostname=settings.CLUSTER_HOST_ID)
node = self.filter(hostname=self.my_hostname())
if node.exists():
return node[0]
raise RuntimeError("No instance found with the current cluster host id")