Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing task desc croping(cf #27) #95

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions huey_monitor/tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def __init__(self,
# We call .update() that will not validate the data, so a overlong
# description will raise a database error and maybe a user doesn't know
# what's happen ;)
raise ValidationError(
'Process info description overlong: %(desc)r',
params={'desc': self.desc},
logger.warning(
"Process info description '%(desc)r' has been cropped to maximum authorized value (%(max_length)r)",
params={'desc': self.desc, 'max_length': TASK_MODEL_DESC_MAX_LENGTH,}
)
Skrattoune marked this conversation as resolved.
Show resolved Hide resolved
Skrattoune marked this conversation as resolved.
Show resolved Hide resolved
self.desc = self.desc[:TASK_MODEL_DESC_MAX_LENGTH]

TaskModel.objects.filter(task_id=task.id).update(
desc=self.desc,
Expand Down
13 changes: 11 additions & 2 deletions huey_monitor_tests/tests/test_tqdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def test_process_description_overlong(self):

max_length_txt = 'X' * max_length
overlong_txt = 'Y' * (max_length + 1)
cropped_overlong_txt = 'Y' * max_length

task = Task(id='00000000-0000-0000-0000-000000000001')

Expand All @@ -184,6 +185,14 @@ def test_process_description_overlong(self):
]

# Overlong description should be cut:
msg = f'["Process info description overlong: \'{overlong_txt}\'"]'
with self.assertRaisesMessage(ValidationError, msg):
with self.assertLogs('huey_monitor.tqdm') as logs:
ProcessInfo(task, desc=overlong_txt, total=999)
instance = TaskModel.objects.get()
assert instance.desc == cropped_overlong_txt

assert logs.output == [
(
'INFO:huey_monitor.tqdm:Init TaskModel Task'
f' - {cropped_overlong_txt} 0/999 (divisor: 1000)'
)
]