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 d51fdb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
3 changes: 0 additions & 3 deletions pulpcore/tasking/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import sys
import threading
import time
from datetime import datetime, timedelta
from gettext import gettext as _
from opentelemetry.metrics import get_meter, Observation

from django.conf import settings
from django.db import connection, transaction
Expand All @@ -28,7 +26,6 @@
from pulpcore.constants import TASK_FINAL_STATES, TASK_STATES, VAR_TMP_PULP
from pulpcore.exceptions import AdvisoryLockError
from pulpcore.tasking.tasks import dispatch, execute_task
from pulpcore.app.models import Worker, Task

_logger = logging.getLogger(__name__)

Expand Down
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 d51fdb5

Please sign in to comment.