添加数据分库;

修复taskManager中异步方法没有正常等待的错误;
删除无用的异常捕获;
This commit is contained in:
2024-01-19 11:17:22 +08:00
parent 45ad15a065
commit 8da3110ecd
12 changed files with 94 additions and 61 deletions

View File

@@ -76,8 +76,7 @@ public partial class MySqlDestination : IDisposable, IAsyncDisposable
}
catch (Exception e)
{
_logger.LogCritical(e, "Error when flushing records, sql: {Sql}", cmd.CommandText.Omit(1000));
_context.AddException(e);
_logger.LogError(e, "Error when flushing records, sql: {Sql}", cmd.CommandText.Omit(1000));
var match = MatchTableName().Match(cmd.CommandText);
if (match is { Success: true, Groups.Count: > 1 })
@@ -92,8 +91,7 @@ public partial class MySqlDestination : IDisposable, IAsyncDisposable
}
catch (Exception e)
{
_logger.LogCritical(e, "Error when serialize records, record:");
_context.AddException(e);
_logger.LogError(e, "Error when serialize records, record:");
}
finally
{

View File

@@ -8,7 +8,6 @@ public class ProcessContext
private int _inputCount;
private int _transformCount;
private int _outputCount;
private IList<Exception> _exceptionList = new List<Exception>();
public bool IsInputCompleted { get; private set; }
public bool IsTransformCompleted { get; private set; }
public bool IsOutputCompleted { get; private set; }
@@ -30,14 +29,7 @@ public class ProcessContext
get => _outputCount;
private set => _outputCount = value;
}
public void AddException(Exception ex)
{
_exceptionList.Add(ex);
}
public IList<Exception> GetExceptions()
{
return _exceptionList;
}
public void CompleteInput() => IsInputCompleted = true;
public void CompleteTransform() => IsTransformCompleted = true;

View File

@@ -21,13 +21,14 @@ public class TaskManager
_logger = logger;
}
public void CreateTask<TResult>(Func<TResult> func, CancellationToken cancellationToken = default)
public void CreateTask(Func<Task> func, CancellationToken cancellationToken = default)
{
var task = Task.Factory.StartNew(func, cancellationToken);
var task = Task.Run(func, cancellationToken);
_tasks.Add(task);
_logger.LogDebug("New task created");
}
public void CreateTasks<TResult>(Func<TResult> func,int taskCount, CancellationToken cancellationToken = default)
public void CreateTasks(Func<Task> func,int taskCount, CancellationToken cancellationToken = default)
{
for (int i = 0; i < taskCount; i++)
{