Skip to content

Commit b49aa89

Browse files
authored
Merge pull request #107 from boxine/update-req
Cleanup requirements and update them
2 parents 3ae467c + 077f759 commit b49aa89

File tree

4 files changed

+237
-572
lines changed

4 files changed

+237
-572
lines changed

huey_monitor/tqdm.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.core.exceptions import ValidationError
44
from django.utils import timezone
5+
from django.utils.text import Truncator
56
from huey.api import Task
67

78
from huey_monitor.constants import TASK_MODEL_DESC_MAX_LENGTH
@@ -50,10 +51,12 @@ def __init__(self,
5051
if len(self.desc) > TASK_MODEL_DESC_MAX_LENGTH:
5152
# We call .update() that will not validate the data, so a overlong
5253
# description will raise a database error and maybe a user doesn't know
53-
# what's happen ;)
54-
raise ValidationError(
55-
'Process info description overlong: %(desc)r',
56-
params={'desc': self.desc},
54+
# what's happen -> Just crop it.
55+
self.desc = Truncator(self.desc).chars(TASK_MODEL_DESC_MAX_LENGTH)
56+
logger.warning(
57+
'Process info description %r has been cropped maximum allowed %i characters',
58+
self.desc,
59+
TASK_MODEL_DESC_MAX_LENGTH,
5760
)
5861

5962
TaskModel.objects.filter(task_id=task.id).update(

huey_monitor_tests/tests/test_tqdm.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import datetime
2+
import logging
23
import time
34
from pathlib import Path
45
from unittest import mock
@@ -162,8 +163,7 @@ def test_process_description_overlong(self):
162163

163164
# Test with current max length:
164165
max_length = TaskModel._meta.get_field('desc').max_length
165-
assert max_length == TASK_MODEL_DESC_MAX_LENGTH
166-
assert max_length == 128
166+
assert max_length == TASK_MODEL_DESC_MAX_LENGTH == 128
167167

168168
max_length_txt = 'X' * max_length
169169
overlong_txt = 'Y' * (max_length + 1)
@@ -183,7 +183,12 @@ def test_process_description_overlong(self):
183183
)
184184
]
185185

186-
# Overlong description should be cut:
187-
msg = f'["Process info description overlong: \'{overlong_txt}\'"]'
188-
with self.assertRaisesMessage(ValidationError, msg):
186+
# Overlong description will be cut:
187+
with self.assertLogs('huey_monitor.tqdm', level=logging.WARNING) as logs:
189188
ProcessInfo(task, desc=overlong_txt, total=999)
189+
instance = TaskModel.objects.get()
190+
assert len(instance.desc) == TASK_MODEL_DESC_MAX_LENGTH == 128
191+
192+
assert len(logs.output) == 1
193+
log_line = logs.output[0]
194+
assert "YYYYY…' has been cropped maximum allowed 128 characters" in log_line

0 commit comments

Comments
 (0)