Skip to content

Commit

Permalink
Linting issues
Browse files Browse the repository at this point in the history
Close #3821
  • Loading branch information
decko committed Apr 24, 2024
1 parent 6ff90c6 commit 0f45777
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
31 changes: 26 additions & 5 deletions pulpcore/tasking/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,33 @@ def record_unblocked_waiting_tasks_metric(self):
unit="seconds",
)

unblocked_waiting_tasks = Task.objects.filter(unblocked_at__isnull=False, started_at__isnull=True)
unblocked_waiting_tasks_annotated = unblocked_waiting_tasks.annotate(unblocked_for=Value(timezone.now()) - F("unblocked_at"))
unblocked_waiting_tasks_aggregated = unblocked_waiting_tasks_annotated.aggregate(longest_age=Coalesce(Max("unblocked_for"), timezone.timedelta(0)), unblocked_count=Count(Value(1)), unblocked_count_gte_threshold=Count(Case(When(unblocked_for__gte=Value(timezone.timedelta(seconds=5)), then=1))))
unblocked_waiting_tasks = Task.objects.filter(
unblocked_at__isnull=False, started_at__isnull=True
)
unblocked_waiting_tasks_annotated = unblocked_waiting_tasks.annotate(
unblocked_for=Value(timezone.now()) - F("unblocked_at")
)
unblocked_waiting_tasks_aggregated = (
unblocked_waiting_tasks_annotated.aggregate(
longest_age=Coalesce(Max("unblocked_for"), timezone.timedelta(0)),
unblocked_count=Count(Value(1)),
unblocked_count_gte_threshold=Count(
Case(
When(
unblocked_for__gte=Value(timezone.timedelta(seconds=5)),
then=1,
)
)
),
)
)

unblocked_waiting_tasks_meter.set(unblocked_waiting_tasks_aggregated["unblocked_count"])
longest_waiting_tasks_meter.set(unblocked_waiting_tasks_aggregated["longest_age"].seconds)
unblocked_waiting_tasks_meter.set(
unblocked_waiting_tasks_aggregated["unblocked_count"]
)
longest_waiting_tasks_meter.set(
unblocked_waiting_tasks_aggregated["longest_age"].seconds
)
except AdvisoryLockError:
pass

Expand Down
12 changes: 4 additions & 8 deletions pulpcore/tests/functional/api/test_tasking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import pytest
import subprocess
import time
from time import sleep

import requests
import os

from aiohttp import BasicAuth
from urllib.parse import urljoin
Expand Down Expand Up @@ -356,7 +352,9 @@ def test_task_version_prevent_pickup(dispatch_task, pulpcore_bindings):
pulpcore_bindings.TasksApi.tasks_cancel(task_href, {"state": "canceled"})


def test_emmiting_unblocked_task_telemetry(dispatch_task, pulpcore_bindings, received_otel_metrics, pulpcore_settings):
def test_emmiting_unblocked_task_telemetry(
dispatch_task, pulpcore_bindings, received_otel_metrics, pulpcore_settings
):
if not pulpcore_settings.PULP_OTEL_ENABLED:
pytest.skip("Need PULP_OTEL_ENABLED to run this test.")

Expand All @@ -366,9 +364,7 @@ def test_emmiting_unblocked_task_telemetry(dispatch_task, pulpcore_bindings, rec

resource = str(uuid4())

dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(600,), exclusive_resources=[resource]
)
dispatch_task("pulpcore.app.tasks.test.sleep", args=(600,), exclusive_resources=[resource])
task_href = dispatch_task(
"pulpcore.app.tasks.test.sleep", args=(0,), exclusive_resources=[resource]
)
Expand Down

0 comments on commit 0f45777

Please sign in to comment.