Skip to content

Commit 5887a05

Browse files
committed
refac: make is_queue_full private
1 parent f951507 commit 5887a05

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

api/task_processor/models.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@ def create(
108108
args: typing.Tuple[typing.Any] = None,
109109
kwargs: typing.Dict[str, typing.Any] = None,
110110
) -> "Task":
111-
if queue_size:
112-
if cls.is_queue_full(task_identifier, queue_size):
113-
raise TaskQueueFullError(
114-
f"Queue for task {task_identifier} is full. "
115-
f"Max queue size is {queue_size}"
116-
)
111+
if queue_size and cls._is_queue_full(task_identifier, queue_size):
112+
raise TaskQueueFullError(
113+
f"Queue for task {task_identifier} is full. "
114+
f"Max queue size is {queue_size}"
115+
)
117116
return Task(
118117
task_identifier=task_identifier,
119118
scheduled_for=scheduled_for,
@@ -123,7 +122,7 @@ def create(
123122
)
124123

125124
@classmethod
126-
def is_queue_full(cls, task_identifier: str, queue_size: int) -> bool:
125+
def _is_queue_full(cls, task_identifier: str, queue_size: int) -> bool:
127126
return (
128127
cls.objects.filter(
129128
task_identifier=task_identifier,

api/tests/unit/task_processor/test_unit_task_processor_models.py

-36
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,3 @@ def test_recurring_task_run_should_execute_first_run_at(first_run_time, expected
5959
).should_execute
6060
== expected
6161
)
62-
63-
64-
def test_is_queue_full_returns_true_if_queue_is_full(db):
65-
# Given
66-
task_identifier = "my_callable"
67-
68-
# some incomplete task
69-
for _ in range(10):
70-
Task.objects.create(task_identifier=task_identifier)
71-
72-
Task.create(task_identifier=task_identifier, scheduled_for=timezone.now())
73-
# When
74-
assert Task.is_queue_full(task_identifier, 9) is True
75-
76-
77-
def test_is_queue_full_returns_false_if_queue_is_not_full(db):
78-
# Given
79-
task_identifier = "my_callable"
80-
81-
# Some incomplete task
82-
for _ in range(10):
83-
Task.objects.create(task_identifier=task_identifier)
84-
85-
# tasks with different identifiers
86-
Task.objects.create(task_identifier="task_with_different_identifier")
87-
88-
# failed tasks
89-
Task.objects.create(
90-
task_identifier="task_with_different_identifier", num_failures=3
91-
)
92-
93-
# When
94-
Task.create(task_identifier=task_identifier, scheduled_for=timezone.now())
95-
96-
# Then
97-
assert Task.is_queue_full(task_identifier, 10) is False

0 commit comments

Comments
 (0)