🐛 Fixes in track tasks
This commit is contained in:
@@ -261,7 +261,7 @@ public class FileUploadController(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Update task status to "processing" - background processing is now happening
|
// Update task status to "processing" - background processing is now happening
|
||||||
await persistentTaskService.UpdateTaskProgressAsync(taskId, 95, "Processing file in background...");
|
await persistentTaskService.UpdateTaskProgressAsync(taskId, 0.95, "Processing file in background...");
|
||||||
|
|
||||||
// Send upload completion notification (file is uploaded, but processing continues)
|
// Send upload completion notification (file is uploaded, but processing continues)
|
||||||
await persistentTaskService.SendUploadCompletedNotificationAsync(persistentTask, fileId);
|
await persistentTaskService.SendUploadCompletedNotificationAsync(persistentTask, fileId);
|
||||||
@@ -312,15 +312,13 @@ public class FileUploadController(
|
|||||||
{
|
{
|
||||||
var chunkPath = Path.Combine(taskPath, i + ".chunk");
|
var chunkPath = Path.Combine(taskPath, i + ".chunk");
|
||||||
if (!System.IO.File.Exists(chunkPath))
|
if (!System.IO.File.Exists(chunkPath))
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Chunk " + i + " is missing.");
|
throw new InvalidOperationException("Chunk " + i + " is missing.");
|
||||||
}
|
|
||||||
|
|
||||||
await using var chunkStream = new FileStream(chunkPath, FileMode.Open);
|
await using var chunkStream = new FileStream(chunkPath, FileMode.Open);
|
||||||
await chunkStream.CopyToAsync(mergedStream);
|
await chunkStream.CopyToAsync(mergedStream);
|
||||||
|
|
||||||
// Update progress after each chunk is merged
|
// Update progress after each chunk is merged
|
||||||
var currentProgress = baseProgress + (progressPerChunk * (i + 1));
|
var currentProgress = baseProgress + progressPerChunk * (i + 1);
|
||||||
await persistentTaskService.UpdateTaskProgressAsync(
|
await persistentTaskService.UpdateTaskProgressAsync(
|
||||||
taskId,
|
taskId,
|
||||||
currentProgress,
|
currentProgress,
|
||||||
|
|||||||
@@ -69,11 +69,27 @@ public class PersistentTaskService(
|
|||||||
if (task is null) return;
|
if (task is null) return;
|
||||||
|
|
||||||
var previousProgress = task.Progress;
|
var previousProgress = task.Progress;
|
||||||
|
var delta = progress - previousProgress;
|
||||||
var clampedProgress = Math.Clamp(progress, 0, 1.0);
|
var clampedProgress = Math.Clamp(progress, 0, 1.0);
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
|
||||||
|
// Update the cached task
|
||||||
|
task.Progress = clampedProgress;
|
||||||
|
task.LastActivity = now;
|
||||||
|
task.UpdatedAt = now;
|
||||||
|
if (statusMessage is not null)
|
||||||
|
task.Description = statusMessage;
|
||||||
|
|
||||||
|
await SetCacheAsync(task);
|
||||||
|
|
||||||
|
// Send progress update notification
|
||||||
|
await SendTaskProgressUpdateAsync(task, task.Progress, previousProgress);
|
||||||
|
|
||||||
|
// Only updates when update in period
|
||||||
// Use ExecuteUpdateAsync for better performance - update only the fields we need
|
// Use ExecuteUpdateAsync for better performance - update only the fields we need
|
||||||
var updatedRows = await db.Tasks
|
if (Math.Abs(progress - 1) < 0.1 || delta * 100 > 5)
|
||||||
|
{
|
||||||
|
await db.Tasks
|
||||||
.Where(t => t.TaskId == taskId)
|
.Where(t => t.TaskId == taskId)
|
||||||
.ExecuteUpdateAsync(setters => setters
|
.ExecuteUpdateAsync(setters => setters
|
||||||
.SetProperty(t => t.Progress, clampedProgress)
|
.SetProperty(t => t.Progress, clampedProgress)
|
||||||
@@ -81,22 +97,6 @@ public class PersistentTaskService(
|
|||||||
.SetProperty(t => t.UpdatedAt, now)
|
.SetProperty(t => t.UpdatedAt, now)
|
||||||
.SetProperty(t => t.Description, t => statusMessage ?? t.Description)
|
.SetProperty(t => t.Description, t => statusMessage ?? t.Description)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (updatedRows > 0)
|
|
||||||
{
|
|
||||||
// Update the cached task
|
|
||||||
task.Progress = clampedProgress;
|
|
||||||
task.LastActivity = now;
|
|
||||||
task.UpdatedAt = now;
|
|
||||||
if (statusMessage is not null)
|
|
||||||
{
|
|
||||||
task.Description = statusMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
await SetCacheAsync(task);
|
|
||||||
|
|
||||||
// Send progress update notification
|
|
||||||
await SendTaskProgressUpdateAsync(task, task.Progress, previousProgress);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +384,7 @@ public class PersistentTaskService(
|
|||||||
TaskId = task.TaskId,
|
TaskId = task.TaskId,
|
||||||
Name = task.Name,
|
Name = task.Name,
|
||||||
Type = task.Type.ToString(),
|
Type = task.Type.ToString(),
|
||||||
|
Parameters = task.Parameters,
|
||||||
CreatedAt = task.CreatedAt.ToString()
|
CreatedAt = task.CreatedAt.ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -409,10 +410,6 @@ public class PersistentTaskService(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Only send significant progress updates (every 5% or major milestones)
|
|
||||||
if (Math.Abs(newProgress - previousProgress) < 5 && newProgress < 100 && newProgress > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var data = new TaskProgressData
|
var data = new TaskProgressData
|
||||||
{
|
{
|
||||||
TaskId = task.TaskId,
|
TaskId = task.TaskId,
|
||||||
@@ -634,7 +631,7 @@ public class PersistentTaskService(
|
|||||||
var chunkSize = request.ChunkSize ?? 1024 * 1024 * 5; // 5MB default
|
var chunkSize = request.ChunkSize ?? 1024 * 1024 * 5; // 5MB default
|
||||||
var chunksCount = (int)Math.Ceiling((double)request.FileSize / chunkSize);
|
var chunksCount = (int)Math.Ceiling((double)request.FileSize / chunkSize);
|
||||||
|
|
||||||
// Use default pool if no pool is specified, or find first available pool
|
// Use the default pool if no pool is specified, or find first available pool
|
||||||
var poolId = request.PoolId ?? await GetFirstAvailablePoolIdAsync();
|
var poolId = request.PoolId ?? await GetFirstAvailablePoolIdAsync();
|
||||||
|
|
||||||
var uploadTask = new PersistentUploadTask
|
var uploadTask = new PersistentUploadTask
|
||||||
@@ -1057,6 +1054,7 @@ public class TaskCreatedData
|
|||||||
public string Name { get; set; } = null!;
|
public string Name { get; set; } = null!;
|
||||||
public string Type { get; set; } = null!;
|
public string Type { get; set; } = null!;
|
||||||
public string CreatedAt { get; set; } = null!;
|
public string CreatedAt { get; set; } = null!;
|
||||||
|
public Dictionary<string, object?>? Parameters { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TaskProgressData
|
public class TaskProgressData
|
||||||
|
|||||||
Reference in New Issue
Block a user