Commit 20631e55 by dingsongjie

完善 eventbus 多个实例之间重试时的数据隔离

parent 2d910fc1
...@@ -83,22 +83,27 @@ $"UPDATE {tableName} SET \"Retries\"=@Retries,\"ExpiresAt\"=@ExpiresAt,\"StatusN ...@@ -83,22 +83,27 @@ $"UPDATE {tableName} SET \"Retries\"=@Retries,\"ExpiresAt\"=@ExpiresAt,\"StatusN
$"SELECT * FROM {tableName} WHERE \"Retries\"<{producerOptions.MaxFailedRetryCount} AND \"Added\"<'{fourMinAgo}' AND \"StatusName\"='{EventStatus.Pending}' for update skip locked LIMIT 200;"; $"SELECT * FROM {tableName} WHERE \"Retries\"<{producerOptions.MaxFailedRetryCount} AND \"Added\"<'{fourMinAgo}' AND \"StatusName\"='{EventStatus.Pending}' for update skip locked LIMIT 200;";
var result = new List<EventEntity>(); var result = new List<EventEntity>();
using var connection = new NpgsqlConnection(options.ConnectionString); using (var connection = new NpgsqlConnection(options.ConnectionString))
var reader = await connection.ExecuteReaderAsync(sql);
while (reader.Read())
{ {
result.Add(new EventEntity using (var transaction = await connection.BeginTransactionAsync())
{ {
Id = reader.GetString(0), var reader = await connection.ExecuteReaderAsync(sql);
Name = reader.GetString(2), while (reader.Read())
Content = reader.GetString(3), {
Retries = reader.GetInt32(4), result.Add(new EventEntity
Added = reader.GetDateTime(5), {
StatusName = reader.GetString(7) Id = reader.GetString(0),
}); Name = reader.GetString(2),
Content = reader.GetString(3),
Retries = reader.GetInt32(4),
Added = reader.GetDateTime(5),
StatusName = reader.GetString(7)
});
}
await transaction.CommitAsync();
return result;
}
} }
return result;
} }
public async Task<bool> StoreMessage(EventEntity eventEntity, object dbTransaction = null) public async Task<bool> StoreMessage(EventEntity eventEntity, object dbTransaction = null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment