fix celery task reaper

* celery workers have internal queue names that are named after the
system hostname. This may differ from what tower knows the host by,
Instance.hostname
This adds a mapping so we can convert internal celery names to Instance
names for purposes of reaping jobs.
This commit is contained in:
chris meyers
2018-06-14 15:52:52 -04:00
parent 07323640bc
commit 1359208a99
6 changed files with 97 additions and 19 deletions

View File

@@ -45,6 +45,11 @@ class Instance(BaseModel):
uuid = models.CharField(max_length=40)
hostname = models.CharField(max_length=250, unique=True)
system_hostname = models.CharField(
max_length=255,
db_index=True,
help_text="Machine hostname",
)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
last_isolated_check = models.DateTimeField(
@@ -109,6 +114,10 @@ class Instance(BaseModel):
def jobs_total(self):
return UnifiedJob.objects.filter(execution_node=self.hostname).count()
@property
def celery_system_hostname(self):
return 'celery@{}'.format(self.system_hostname)
def is_lost(self, ref_time=None, isolated=False):
if ref_time is None:
ref_time = now()