events: use colon as separator for task name and task UID

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer 2023-02-13 12:06:29 +01:00
parent 1240ed6c6d
commit 53b25d61f7
No known key found for this signature in database
2 changed files with 5 additions and 10 deletions

View File

@ -18,4 +18,4 @@ def monitoring_set_workers(sender, **kwargs):
def monitoring_set_tasks(sender, **kwargs):
"""Set task gauges"""
for task in TaskInfo.all().values():
task.set_prom_metrics()
task.update_metrics()

View File

@ -63,11 +63,6 @@ class TaskInfo:
task_description: Optional[str] = field(default=None)
@property
def html_name(self) -> list[str]:
"""Get task_name, but split on underscores, so we can join in the html template."""
return self.task_name.split("_")
@staticmethod
def all() -> dict[str, "TaskInfo"]:
"""Get all TaskInfo objects"""
@ -82,7 +77,7 @@ class TaskInfo:
"""Delete task info from cache"""
return cache.delete(CACHE_KEY_PREFIX + self.task_name)
def set_prom_metrics(self):
def update_metrics(self):
"""Update prometheus metrics"""
start = default_timer()
if hasattr(self, "start_timestamp"):
@ -101,9 +96,9 @@ class TaskInfo:
"""Save task into cache"""
key = CACHE_KEY_PREFIX + self.task_name
if self.result.uid:
key += f"/{self.result.uid}"
self.task_name += f"/{self.result.uid}"
self.set_prom_metrics()
key += f":{self.result.uid}"
self.task_name += f":{self.result.uid}"
self.update_metrics()
cache.set(key, self, timeout=timeout_hours * 60 * 60)