mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Fix: incorrect progress updating (#8253)
### What problem does this PR solve? Progress is only updated if it's valid and not regressive. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import xxhash
|
import xxhash
|
||||||
@ -256,36 +257,55 @@ class TaskService(CommonService):
|
|||||||
@DB.connection_context()
|
@DB.connection_context()
|
||||||
def update_progress(cls, id, info):
|
def update_progress(cls, id, info):
|
||||||
"""Update the progress information for a task.
|
"""Update the progress information for a task.
|
||||||
|
|
||||||
This method updates both the progress message and completion percentage of a task.
|
This method updates both the progress message and completion percentage of a task.
|
||||||
It handles platform-specific behavior (macOS vs others) and uses database locking
|
It handles platform-specific behavior (macOS vs others) and uses database locking
|
||||||
when necessary to ensure thread safety.
|
when necessary to ensure thread safety.
|
||||||
|
|
||||||
|
Update Rules:
|
||||||
|
- progress_msg: Always appends the new message to the existing one, and trims the result to max 3000 lines.
|
||||||
|
- progress: Only updates if the current progress is not -1 AND
|
||||||
|
(the new progress is -1 OR greater than the existing progress),
|
||||||
|
to avoid overwriting valid progress with invalid or regressive values.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
id (str): The unique identifier of the task to update.
|
id (str): The unique identifier of the task to update.
|
||||||
info (dict): Dictionary containing progress information with keys:
|
info (dict): Dictionary containing progress information with keys:
|
||||||
- progress_msg (str, optional): Progress message to append
|
- progress_msg (str, optional): Progress message to append
|
||||||
- progress (float, optional): Progress percentage (0.0 to 1.0)
|
- progress (float, optional): Progress percentage (0.0 to 1.0)
|
||||||
"""
|
"""
|
||||||
|
task = cls.model.get_by_id(id)
|
||||||
|
if not task:
|
||||||
|
logging.warning("Update_progress error: task not found")
|
||||||
|
return
|
||||||
|
|
||||||
if os.environ.get("MACOS"):
|
if os.environ.get("MACOS"):
|
||||||
if info["progress_msg"]:
|
if info["progress_msg"]:
|
||||||
task = cls.model.get_by_id(id)
|
|
||||||
progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000)
|
progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000)
|
||||||
cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute()
|
cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute()
|
||||||
if "progress" in info:
|
if "progress" in info:
|
||||||
cls.model.update(progress=info["progress"]).where(
|
prog = info["progress"]
|
||||||
cls.model.id == id
|
cls.model.update(progress=prog).where(
|
||||||
|
(cls.model.id == id) &
|
||||||
|
(
|
||||||
|
(cls.model.progress != -1) &
|
||||||
|
((prog == -1) | (prog > cls.model.progress))
|
||||||
|
)
|
||||||
).execute()
|
).execute()
|
||||||
return
|
return
|
||||||
|
|
||||||
with DB.lock("update_progress", -1):
|
with DB.lock("update_progress", -1):
|
||||||
if info["progress_msg"]:
|
if info["progress_msg"]:
|
||||||
task = cls.model.get_by_id(id)
|
|
||||||
progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000)
|
progress_msg = trim_header_by_lines(task.progress_msg + "\n" + info["progress_msg"], 3000)
|
||||||
cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute()
|
cls.model.update(progress_msg=progress_msg).where(cls.model.id == id).execute()
|
||||||
if "progress" in info:
|
if "progress" in info:
|
||||||
cls.model.update(progress=info["progress"]).where(
|
prog = info["progress"]
|
||||||
cls.model.id == id
|
cls.model.update(progress=prog).where(
|
||||||
|
(cls.model.id == id) &
|
||||||
|
(
|
||||||
|
(cls.model.progress != -1) &
|
||||||
|
((prog == -1) | (prog > cls.model.progress))
|
||||||
|
)
|
||||||
).execute()
|
).execute()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user