diff --git a/coriolis/db/api.py b/coriolis/db/api.py index af9b712e0..f9b3ca271 100644 --- a/coriolis/db/api.py +++ b/coriolis/db/api.py @@ -869,10 +869,18 @@ def _get_progress_update(context, task_id, index): def add_task_progress_update( context, task_id, message, initial_step=0, total_steps=0): task_progress_update = models.TaskProgressUpdate() - task_progress_update.id = str(uuid.uuid4()) + task_event_id = str(uuid.uuid4()) + task_progress_update.id = task_event_id task_progress_update.task_id = task_id task_progress_update.current_step = initial_step task_progress_update.total_steps = total_steps + max_msg_len = models.MAX_EVENT_MESSAGE_LENGHT + if len(message) > max_msg_len: + LOG.warn( + f"Progress message for task '{task_id}' with ID '{task_event_id}'" + f"is too long. Truncating before insertion. " + f"Original message was: '{message}'") + message = f"{message[:max_msg_len-len('...')]}..." task_progress_update.message = message task_progress_update.index = 0 @@ -899,6 +907,14 @@ def update_task_progress_update( if new_total_steps is not None: task_progress_update.total_steps = new_total_steps if new_message is not None: + max_msg_len = models.MAX_EVENT_MESSAGE_LENGHT + if len(new_message) > max_msg_len: + task_event_id = task_progress_update.id + LOG.warn( + f"Progress message for task '{task_id}' with ID " + f"'{task_event_id}' is too long. Truncating before insertion." + f" Original message was: '{new_message}'") + new_message = f"{new_message[:max_msg_len-len('...')]}..." task_progress_update.message = new_message diff --git a/coriolis/db/sqlalchemy/models.py b/coriolis/db/sqlalchemy/models.py index bd5da9881..f326837ef 100644 --- a/coriolis/db/sqlalchemy/models.py +++ b/coriolis/db/sqlalchemy/models.py @@ -14,9 +14,12 @@ BASE = declarative.declarative_base() +MAX_EVENT_MESSAGE_LENGHT = 1024 + class TaskEvent(BASE, models.TimestampMixin, models.SoftDeleteMixin, models.ModelBase): + __tablename__ = 'task_event' id = sqlalchemy.Column(sqlalchemy.String(36), @@ -27,7 +30,8 @@ class TaskEvent(BASE, models.TimestampMixin, models.SoftDeleteMixin, nullable=False) level = sqlalchemy.Column(sqlalchemy.String(20), nullable=False) index = sqlalchemy.Column(sqlalchemy.Integer, nullable=False) - message = sqlalchemy.Column(sqlalchemy.String(1024), nullable=False) + message = sqlalchemy.Column( + sqlalchemy.String(MAX_EVENT_MESSAGE_LENGHT), nullable=False) def to_dict(self): result = {