diff --git a/client/Antares.Service.Assets.Client/AssetsServiceUserDataClient.cs b/client/Antares.Service.Assets.Client/AssetsServiceUserDataClient.cs index e25482f..f34bb28 100644 --- a/client/Antares.Service.Assets.Client/AssetsServiceUserDataClient.cs +++ b/client/Antares.Service.Assets.Client/AssetsServiceUserDataClient.cs @@ -6,6 +6,8 @@ using System.Threading.Tasks; using Antares.Service.Assets.Client.Models; using Autofac; +using Common.Log; +using Lykke.Common.Log; using Lykke.Service.Assets.Client; using Lykke.Service.Assets.Client.Models; using Lykke.Service.Assets.Core.Domain; @@ -21,14 +23,21 @@ public class AssetsServiceUserDataClient: IStartable, IDisposable, IAssetsServic private readonly AssetsServiceHttp _httpClient; private readonly IMyNoSqlServerDataReader _readerAssetConditionNoSql; + private readonly IMyNoSqlServerDataReader _readerWatchListCustomNoSql; + private MyNoSqlReadRepository _readerWatchListPredefinedNoSql; + private ILog _log; - public AssetsServiceUserDataClient(string myNoSqlServerReaderHostPort, string assetServiceHttpApiUrl) + + public AssetsServiceUserDataClient(string myNoSqlServerReaderHostPort, string assetServiceHttpApiUrl, ILogFactory logFactory) { + _log = logFactory.CreateLog(this); var host = Environment.GetEnvironmentVariable("HOST") ?? Environment.MachineName; _httpClient = new AssetsServiceHttp(new Uri(assetServiceHttpApiUrl)); _myNoSqlClient = new MyNoSqlTcpClient(() => myNoSqlServerReaderHostPort, host); _readerAssetConditionNoSql = new MyNoSqlReadRepository(_myNoSqlClient, AssetConditionNoSql.TableName); + _readerWatchListCustomNoSql = new MyNoSqlReadRepository(_myNoSqlClient, WatchListCustomNoSql.TableNameCustomWatchList); + _readerWatchListPredefinedNoSql = new MyNoSqlReadRepository(_myNoSqlClient, WatchListPredefinedNoSql.TableNamePredefinedWatchList); } public void Start() @@ -41,13 +50,13 @@ public void Start() while (iteration < 100) { iteration++; - //if (Assets.GetAll().Count > 0 && AssetExtendedInfo.GetAll().Count > 0 && AssetPairs.GetAll().Count > 0) - break; + if (_readerWatchListPredefinedNoSql.Count() > 0) + break; Thread.Sleep(100); } sw.Stop(); - Console.WriteLine($"AssetsWatchLists client is started. Wait time: {sw.ElapsedMilliseconds} ms"); + Console.WriteLine($"AssetsServiceUserDataClient client is started. Wait time: {sw.ElapsedMilliseconds} ms"); } public void Dispose() @@ -59,6 +68,29 @@ public void Dispose() public IAvailableAssetClient AvailableAssets => this; public IAssetsServiceHttp HttpClient => _httpClient; + async Task> IAvailableAssetClient.GetAssetIds(string clientId, bool isIosDevice) + { + try + { + var data = _readerAssetConditionNoSql.Get( + AssetConditionNoSql.GeneratePartitionKey(clientId), + AssetConditionNoSql.GenerateRowKey()); + + if (data?.AssetConditions != null) + { + return data.AssetConditions.Where(o => o.AvailableToClient == true).Select(o => o.Asset).ToList(); + } + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from MyNoSQL. Table: ${AssetConditionNoSql.TableName}, PK: {AssetConditionNoSql.GeneratePartitionKey(clientId)}, RK: {AssetConditionNoSql.GenerateRowKey()}"); + throw; + } + + var result = await HttpClient.ClientGetAssetIdsAsync(clientId, isIosDevice); + return result.ToList(); + } + async Task IWatchListsClient.AddCustomAsync(WatchListDto watchList, string clientId) { var result = await HttpClient.WatchListAddCustomAsync(FromWatchListDto(watchList), clientId); @@ -76,13 +108,6 @@ async Task IWatchListsClient.RemoveCustomAsync(string watchListId, string client await HttpClient.WatchListCustomRemoveWithHttpMessagesAsync(watchListId, clientId); } - async Task> IWatchListsClient.GetAllCustom(string clientId) - { - var result = await HttpClient.WatchListGetAllCustomAsync(clientId); - var data = result.Select(e => (IWatchList) FromWatchListResponse(e)).ToList(); - return data; - } - async Task IWatchListsClient.AddPredefinedAsync(WatchListDto watchList) { var result = await HttpClient.WatchListAddPredefinedAsync(FromWatchListDto(watchList)); @@ -95,41 +120,92 @@ async Task IWatchListsClient.UpdatePredefinedAsync(WatchListDto watchList) await HttpClient.WatchListUpdatePredefinedAsync(FromWatchListDto(watchList)); } + async Task IWatchListsClient.GetCustomWatchListAsync(string clientId, string watchListId) { - var result = await HttpClient.WatchListGetCustomAsync(watchListId, clientId); - var data = FromWatchListResponse(result); - return data; + try + { + var data = _readerWatchListCustomNoSql.Get(WatchListCustomNoSql.GeneratePartitionKey(clientId), WatchListCustomNoSql.GenerateRowKey(watchListId)); + + if (data != null) + { + return data; + } + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from MyNoSQL. Table: ${WatchListCustomNoSql.TableNameCustomWatchList}, PK: {WatchListCustomNoSql.GeneratePartitionKey(clientId)}", ex); + } + + try + { + var result = await HttpClient.WatchListGetCustomAsync(watchListId, clientId); + var data = FromWatchListResponse(result); + return data; + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from API. Method: WatchListGetCustomAsync, clientId: {clientId}, watchListId: {watchListId}"); + throw; + } } async Task IWatchListsClient.GetPredefinedWatchListAsync(string watchListId) { - var result = await HttpClient.WatchListGetPredefinedAsync(watchListId); - var data = FromWatchListResponse(result); - return data; + try + { + var data = _readerWatchListCustomNoSql.Get(WatchListPredefinedNoSql.GeneratePartitionKey(), WatchListPredefinedNoSql.GenerateRowKey(watchListId)); + + if (data != null) + { + return data; + } + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from MyNoSQL. Table: ${WatchListPredefinedNoSql.TableNamePredefinedWatchList}, PK: {WatchListPredefinedNoSql.GeneratePartitionKey()}, RK: {WatchListPredefinedNoSql.GenerateRowKey(watchListId)}", ex); + } + + try + { + var result = await HttpClient.WatchListGetPredefinedAsync(watchListId); + var data = FromWatchListResponse(result); + return data; + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from API. Method: WatchListGetPredefinedAsync, watchListId: {watchListId}"); + throw; + } } - async Task> IAvailableAssetClient.GetAssetIds(string clientId, bool isIosDevice) + async Task> IWatchListsClient.GetAllCustom(string clientId) { try { - var data = _readerAssetConditionNoSql.Get( - AssetConditionNoSql.GeneratePartitionKey(clientId), - AssetConditionNoSql.GenerateRowKey()); + var data = _readerWatchListCustomNoSql.Get(WatchListCustomNoSql.GeneratePartitionKey(clientId)); - if (data?.AssetConditions != null) + if (data != null) { - return data.AssetConditions.Where(o => o.AvailableToClient == true).Select(o => o.Asset).ToList(); + return data.Select(e => (IWatchList)e).ToList(); } } catch (Exception ex) { - Console.WriteLine($"Cannot read from MyNoSQL. Table: ${AssetConditionNoSql.TableName}, PK: {AssetConditionNoSql.GeneratePartitionKey(clientId)}, RK: {AssetConditionNoSql.GenerateRowKey()}, Ex: {ex}"); + _log.Error(ex, $"Cannot read from MyNoSQL. Table: ${WatchListCustomNoSql.TableNameCustomWatchList}, PK: {WatchListCustomNoSql.GeneratePartitionKey(clientId)}", ex); + } + + try + { + var result = await HttpClient.WatchListGetAllCustomAsync(clientId); + var resultData = result.Select(e => (IWatchList) FromWatchListResponse(e)).ToList(); + return resultData; + } + catch (Exception ex) + { + _log.Error(ex, $"Cannot read from API. Method: WatchListGetAllCustomAsync, clientId: {clientId}"); throw; } - - var result = await HttpClient.ClientGetAssetIdsAsync(clientId, isIosDevice); - return result.ToList(); } private WatchListDto FromWatchListResponse(WatchList item) diff --git a/client/Antares.Service.Assets.Client/IAssetsServiceUserDataClient.cs b/client/Antares.Service.Assets.Client/IAssetsServiceUserDataClient.cs index c002479..b5e4912 100644 --- a/client/Antares.Service.Assets.Client/IAssetsServiceUserDataClient.cs +++ b/client/Antares.Service.Assets.Client/IAssetsServiceUserDataClient.cs @@ -20,10 +20,10 @@ public interface IWatchListsClient Task AddCustomAsync(WatchListDto watchList, string clientId); Task UpdateCustomWatchListAsync(string clientId, WatchListDto watchList); Task RemoveCustomAsync(string watchListId, string clientId); - Task> GetAllCustom(string clientId); - Task AddPredefinedAsync(WatchListDto watchList); Task UpdatePredefinedAsync(WatchListDto watchList); + + Task> GetAllCustom(string clientId); Task GetCustomWatchListAsync(string clientId, string watchListId); Task GetPredefinedWatchListAsync(string watchListId); } diff --git a/src/Lykke.Service.Assets.NoSql/Models/WatchListCustomNoSql.cs b/src/Lykke.Service.Assets.NoSql/Models/WatchListCustomNoSql.cs new file mode 100644 index 0000000..fc66d71 --- /dev/null +++ b/src/Lykke.Service.Assets.NoSql/Models/WatchListCustomNoSql.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Linq; +using Lykke.Service.Assets.Core.Domain; +using MyNoSqlServer.Abstractions; + +namespace Lykke.Service.Assets.NoSql.Models +{ + public class WatchListCustomNoSql : MyNoSqlDbEntity, IWatchList + { + public const string TableNameCustomWatchList = "antares.asset.custom-watch-list"; + + public static string GeneratePartitionKey(string clientId) => clientId; + public static string GenerateRowKey(string watchListId) => watchListId; + + public string ClientId { get; set; } + + public List AssetIds { get; set; } + public string Id { get; set; } + public string Name { get; set; } + public int Order { get; set; } + public bool ReadOnly { get; set; } + + IEnumerable IWatchList.AssetIds => AssetIds; + + public static WatchListCustomNoSql Create(string clientId, IWatchList watchList) + { + return new WatchListCustomNoSql() + { + PartitionKey = GeneratePartitionKey(clientId), + RowKey = GenerateRowKey(watchList.Id), + Id = watchList.Id, + Name = watchList.Name, + Order = watchList.Order, + ClientId = clientId, + ReadOnly = watchList.ReadOnly, + AssetIds = watchList.AssetIds.ToList() + }; + } + } +} diff --git a/src/Lykke.Service.Assets.NoSql/Models/WatchListPredefinedNoSql.cs b/src/Lykke.Service.Assets.NoSql/Models/WatchListPredefinedNoSql.cs new file mode 100644 index 0000000..9bb6b49 --- /dev/null +++ b/src/Lykke.Service.Assets.NoSql/Models/WatchListPredefinedNoSql.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using System.Linq; +using Lykke.Service.Assets.Core.Domain; +using MyNoSqlServer.Abstractions; + +namespace Lykke.Service.Assets.NoSql.Models +{ + public class WatchListPredefinedNoSql : MyNoSqlDbEntity, IWatchList + { + public const string TableNamePredefinedWatchList = "antares.asset.predefined-watch-list"; + + public static string GeneratePartitionKey() => "predefined"; + public static string GenerateRowKey(string watchListId) => watchListId; + + public List AssetIds { get; set; } + public string Id { get; set; } + public string Name { get; set; } + public int Order { get; set; } + public bool ReadOnly { get; set; } + + IEnumerable IWatchList.AssetIds => AssetIds; + + public static WatchListPredefinedNoSql Create(IWatchList watchList) + { + return new WatchListPredefinedNoSql() + { + PartitionKey = GeneratePartitionKey(), + RowKey = GenerateRowKey(watchList.Id), + Id = watchList.Id, + Name = watchList.Name, + Order = watchList.Order, + ReadOnly = watchList.ReadOnly, + AssetIds = watchList.AssetIds.ToList() + }; + } + } +} diff --git a/src/Lykke.Service.Assets.Services/AssetConditionService.cs b/src/Lykke.Service.Assets.Services/AssetConditionService.cs index 5ac1955..227eb15 100644 --- a/src/Lykke.Service.Assets.Services/AssetConditionService.cs +++ b/src/Lykke.Service.Assets.Services/AssetConditionService.cs @@ -79,23 +79,28 @@ public async Task GetDefaultLayerAsync() return model; } - public Task AddAssetConditionAsync(string layerId, IAssetCondition assetCondition) + public async Task AddAssetConditionAsync(string layerId, IAssetCondition assetCondition) { - return _cachedAssetConditionsService.AddAssetConditionAsync(layerId, assetCondition); + await _myNoSqlWriter.Clear(); + await _cachedAssetConditionsService.AddAssetConditionAsync(layerId, assetCondition); } - public Task UpdateAssetConditionAsync(string layerId, IAssetCondition assetCondition) + public async Task UpdateAssetConditionAsync(string layerId, IAssetCondition assetCondition) { - return _cachedAssetConditionsService.AddAssetConditionAsync(layerId, assetCondition); + await _myNoSqlWriter.Clear(); + await _cachedAssetConditionsService.AddAssetConditionAsync(layerId, assetCondition); } - public Task DeleteAssetConditionAsync(string layerId, string assetId) + public async Task DeleteAssetConditionAsync(string layerId, string assetId) { - return _cachedAssetConditionsService.DeleteAssetConditionAsync(layerId, assetId); + await _myNoSqlWriter.Clear(); + await _cachedAssetConditionsService.DeleteAssetConditionAsync(layerId, assetId); } public async Task AddDefaultAssetConditionAsync(string layerId, IAssetDefaultCondition assetDefaultCondition) { + await _myNoSqlWriter.Clear(); + await _assetDefaultConditionRepository.InsertOrReplaceAsync(layerId, assetDefaultCondition); await _cacheManager.ClearCacheAsync("Added default asset condition"); @@ -103,6 +108,8 @@ public async Task AddDefaultAssetConditionAsync(string layerId, IAssetDefaultCon public async Task UpdateDefaultAssetConditionAsync(string layerId, IAssetDefaultCondition assetDefaultCondition) { + await _myNoSqlWriter.Clear(); + await _assetDefaultConditionRepository.InsertOrReplaceAsync(layerId, assetDefaultCondition); await _cacheManager.ClearCacheAsync("Updated default asset condition"); @@ -110,6 +117,8 @@ public async Task UpdateDefaultAssetConditionAsync(string layerId, IAssetDefault public async Task DeleteDefaultAssetConditionAsync(string layerId) { + await _myNoSqlWriter.Clear(); + await _assetDefaultConditionRepository.DeleteAsync(layerId); await _cacheManager.ClearCacheAsync("Deleted default asset condition"); @@ -122,6 +131,8 @@ public async Task AddLayerAsync(IAssetConditionLayer layer) public async Task UpdateLayerAsync(IAssetConditionLayer layer) { + await _myNoSqlWriter.Clear(); + await _assetConditionLayerRepository.InsertOrReplaceAsync(layer); await _cacheManager.ClearCacheAsync("Updated condition layer"); @@ -129,6 +140,8 @@ public async Task UpdateLayerAsync(IAssetConditionLayer layer) public async Task DeleteLayerAsync(string layerId) { + await _myNoSqlWriter.Clear(); + await Task.WhenAll( _assetConditionLayerLinkClientRepository.RemoveLayerFromClientsAsync(layerId), _cachedAssetConditionsService.DeleteAssetConditionsAsync(layerId), @@ -140,6 +153,8 @@ await Task.WhenAll( public async Task UpdateDefaultLayerAsync(IAssetConditionLayerSettings settings) { + await _myNoSqlWriter.Clear(); + await _assetDefaultConditionLayerRepository.InsertOrReplaceAsync(settings); await _cacheManager.ClearCacheAsync("Default asset condition layer changed"); @@ -165,6 +180,8 @@ public async Task> GetClientLayers(string clie public async Task AddClientLayerAsync(string clientId, string layerId) { + await _myNoSqlWriter.TryDeleteAsync(AssetConditionNoSql.GeneratePartitionKey(clientId), AssetConditionNoSql.GenerateRowKey()); + await _assetConditionLayerLinkClientRepository.AddAsync(clientId, layerId); await _cacheManager.RemoveClientFromCacheAsync(clientId); @@ -172,6 +189,8 @@ public async Task AddClientLayerAsync(string clientId, string layerId) public async Task RemoveClientLayerAsync(string clientId, string layerId) { + await _myNoSqlWriter.TryDeleteAsync(AssetConditionNoSql.GeneratePartitionKey(clientId), AssetConditionNoSql.GenerateRowKey()); + await _assetConditionLayerLinkClientRepository.RemoveAsync(clientId, layerId); await _cacheManager.RemoveClientFromCacheAsync(clientId); diff --git a/src/Lykke.Service.Assets.Services/MyNoSqlWriterWrapper.cs b/src/Lykke.Service.Assets.Services/MyNoSqlWriterWrapper.cs index e9fbbf2..2275c83 100644 --- a/src/Lykke.Service.Assets.Services/MyNoSqlWriterWrapper.cs +++ b/src/Lykke.Service.Assets.Services/MyNoSqlWriterWrapper.cs @@ -16,6 +16,8 @@ namespace Lykke.Service.Assets.Services Task TryDeleteAsync(string partitionKey, string rowKey); void Start(Func> readAllRecordsCallback, TimeSpan? reloadTimerPeriod = null); void StartWithClearing(int countInCache, TimeSpan? reloadTimerPeriod = null); + Task CleanAndBulkInsertAsync(string partitionKey, IEnumerable list); + Task Clear(); } public class MyNoSqlWriterWrapper : IDisposable, IMyNoSqlWriterWrapper where TEntity : IMyNoSqlDbEntity, new() @@ -108,6 +110,16 @@ public void StartWithClearing(int countInCache, TimeSpan? reloadTimerPeriod = nu _log.Info($"Started wrapper MyNoSql table for entity {typeof(TEntity).Name}"); } + public async Task Clear() + { + await _writer.CleanAndKeepMaxPartitions(0); + } + + public async Task CleanAndBulkInsertAsync(string partitionKey, IEnumerable list) + { + await _writer.CleanAndBulkInsertAsync(partitionKey, list); + } + private void DoTimer(object state) { lock (_sync) diff --git a/src/Lykke.Service.Assets.Services/WatchListService.cs b/src/Lykke.Service.Assets.Services/WatchListService.cs index 23edb1d..3d5637a 100644 --- a/src/Lykke.Service.Assets.Services/WatchListService.cs +++ b/src/Lykke.Service.Assets.Services/WatchListService.cs @@ -2,31 +2,48 @@ using System.Collections.Generic; using System.Threading.Tasks; using System.Linq; +using Autofac; +using Common.Log; +using Lykke.Common.Log; using Lykke.Service.Assets.Core; using Lykke.Service.Assets.Core.Domain; using Lykke.Service.Assets.Core.Repositories; using Lykke.Service.Assets.Core.Services; +using Lykke.Service.Assets.NoSql.Models; namespace Lykke.Service.Assets.Services { - public class WatchListService : IWatchListService + public class WatchListService : IWatchListService, IStartable { private readonly ICustomWatchListRepository _customWatchListRepository; private readonly IPredefinedWatchListRepository _predefinedWatchListRepository; + private readonly IMyNoSqlWriterWrapper _myNoSqlWriterCustom; + private readonly IMyNoSqlWriterWrapper _myNoSqlWriterPredefined; + private readonly int _maxClientsInNoSqlCache; + private ILog _log; public WatchListService( ICustomWatchListRepository customWatchListRepository, - IPredefinedWatchListRepository predefinedWatchListRepository) + IPredefinedWatchListRepository predefinedWatchListRepository, + IMyNoSqlWriterWrapper myNoSqlWriterCustom, + ILogFactory logFactory, + IMyNoSqlWriterWrapper myNoSqlWriterPredefined, + int maxClientsInNoSqlCache) { + _log = logFactory.CreateLog(this); _customWatchListRepository = customWatchListRepository; _predefinedWatchListRepository = predefinedWatchListRepository; + _myNoSqlWriterCustom = myNoSqlWriterCustom; + _maxClientsInNoSqlCache = maxClientsInNoSqlCache; + _myNoSqlWriterPredefined = myNoSqlWriterPredefined; } public async Task AddCustomAsync(string userId, IWatchList watchList) { await _customWatchListRepository.UpsertAsync(userId, watchList); + await ReLoadCustomWatchListToNoSqlCache(userId); return watchList; } @@ -34,6 +51,8 @@ public async Task AddCustomAsync(string userId, IWatchList watchList public async Task AddPredefinedAsync(IWatchList watchList) { await _predefinedWatchListRepository.UpsertAsync(watchList); + await _myNoSqlWriterPredefined.TryInsertOrReplaceAsync(WatchListPredefinedNoSql.Create(watchList)); + return watchList; } @@ -79,7 +98,8 @@ public async Task> GetAllAsync(string userId) public async Task> GetAllCustomAsync(string userId) { - return await _customWatchListRepository.GetAllAsync(userId); + var data = await ReLoadCustomWatchListToNoSqlCache(userId); + return data; } public async Task> GetAllPredefinedAsync() @@ -89,6 +109,7 @@ public async Task> GetAllPredefinedAsync() public async Task GetCustomAsync(string userId, string watchListId) { + await ReLoadCustomWatchListToNoSqlCache(userId); return await _customWatchListRepository.GetAsync(userId, watchListId); } @@ -100,21 +121,25 @@ public async Task GetPredefinedAsync(string watchListId) public async Task RemoveCustomAsync(string userId, string watchListId) { await _customWatchListRepository.RemoveAsync(userId, watchListId); + await ReLoadCustomWatchListToNoSqlCache(userId); } public async Task RemovePredefinedAsync(string watchListId) { await _predefinedWatchListRepository.RemoveAsync(watchListId); + await _myNoSqlWriterPredefined.TryDeleteAsync(WatchListPredefinedNoSql.GeneratePartitionKey(), WatchListPredefinedNoSql.GenerateRowKey(watchListId)); } public async Task UpdateCustomAsync(string userId, IWatchList watchList) { await _customWatchListRepository.UpsertAsync(userId, watchList); + await ReLoadCustomWatchListToNoSqlCache(userId); } public async Task UpdatePredefinedAsync(IWatchList watchList) { await _predefinedWatchListRepository.UpsertAsync(watchList); + await _myNoSqlWriterPredefined.TryInsertOrReplaceAsync(WatchListPredefinedNoSql.Create(watchList)); } private static bool IsAllAssetsWatchList(IWatchList watchList) @@ -122,5 +147,35 @@ private static bool IsAllAssetsWatchList(IWatchList watchList) // Legacy. Probably, we should use settings to detect all assets watch list. return watchList.Name.Equals(Constants.AllAssetsWatchListName, StringComparison.InvariantCultureIgnoreCase); } + + public void Start() + { + _myNoSqlWriterCustom.StartWithClearing(_maxClientsInNoSqlCache); + _myNoSqlWriterPredefined.Start(ReadAllPredefined); + } + + private IList ReadAllPredefined() + { + var data = _predefinedWatchListRepository.GetAllAsync().GetAwaiter().GetResult(); + return data.Select(WatchListPredefinedNoSql.Create).ToList(); + } + + private async Task> ReLoadCustomWatchListToNoSqlCache(string clientId) + { + try + { + var data = await _customWatchListRepository.GetAllAsync(clientId); + var list = data.Select(e => WatchListCustomNoSql.Create(clientId, e)).ToList(); + await _myNoSqlWriterCustom.CleanAndBulkInsertAsync(WatchListCustomNoSql.GeneratePartitionKey(clientId), + list); + + return list; + } + catch(Exception ex) + { + _log.Error(ex, $"Cannot execute CleanAndBulkInsertAsync in NoSql. ClientId: {clientId}"); + throw; + } + } } } diff --git a/src/Lykke.Service.Assets/Modules/MyNoSqlModule.cs b/src/Lykke.Service.Assets/Modules/MyNoSqlModule.cs index 35adaeb..8cf3f7b 100644 --- a/src/Lykke.Service.Assets/Modules/MyNoSqlModule.cs +++ b/src/Lykke.Service.Assets/Modules/MyNoSqlModule.cs @@ -34,8 +34,9 @@ protected override void Load(ContainerBuilder builder) RegisterMyNoSqlWriter(builder, AssetNoSql.TableName); RegisterMyNoSqlWriter(builder, AssetPairNoSql.TableName); RegisterMyNoSqlWriter(builder, AssetConditionNoSql.TableName); + RegisterMyNoSqlWriter(builder, WatchListCustomNoSql.TableNameCustomWatchList); + RegisterMyNoSqlWriter(builder, WatchListPredefinedNoSql.TableNamePredefinedWatchList); - } private void RegisterMyNoSqlWriter(ContainerBuilder builder, string table) diff --git a/src/Lykke.Service.Assets/Modules/ServicesModule.cs b/src/Lykke.Service.Assets/Modules/ServicesModule.cs index 45a3710..00a7dc0 100644 --- a/src/Lykke.Service.Assets/Modules/ServicesModule.cs +++ b/src/Lykke.Service.Assets/Modules/ServicesModule.cs @@ -110,6 +110,9 @@ protected override void Load(ContainerBuilder builder) builder .RegisterType() .As() + .As() + .AutoActivate() + .WithParameter("maxClientsInNoSqlCache", _settings.CurrentValue.AssetsService.MyNoSqlServer.MaxClientsInCache) .SingleInstance(); } } diff --git a/tests/Lykke.Service.Assets.Tests.ConsoleApp/Program.cs b/tests/Lykke.Service.Assets.Tests.ConsoleApp/Program.cs index 778ade2..e83d5e9 100644 --- a/tests/Lykke.Service.Assets.Tests.ConsoleApp/Program.cs +++ b/tests/Lykke.Service.Assets.Tests.ConsoleApp/Program.cs @@ -3,6 +3,8 @@ using System.Threading; using Antares.Service.Assets.Client; using Common; +using Lykke.Common.Log; +using Lykke.Logs; using Lykke.Service.Assets.Client; using Microsoft.Extensions.Logging; using Newtonsoft.Json; @@ -58,11 +60,14 @@ static void Main(string[] args) var assetPairs = client.AssetPairs.GetAll(); Console.WriteLine($"Asset pairs count: {assetPairs.Count}"); - var clientUsder = new AssetsServiceUserDataClient("nosql.share.svc.cluster.local:5125", - "http://assets.lykke-service.svc.cluster.local"); - clientUsder.Start(); + EmptyLogFactory.Instance.CreateLog("test").Info("Hello world"); + + var clientUser = new AssetsServiceUserDataClient("nosql.share.svc.cluster.local:5125", + "http://assets.lykke-service.svc.cluster.local", + EmptyLogFactory.Instance); + clientUser.Start(); - var wl = clientUsder.WatchLists + var wl = clientUser.WatchLists .GetCustomWatchListAsync("fcf49f02-f230-4179-82b6-4d876b0402f9", "f1769fc8-ca6d-4025-a842-515af74e2f6e") .GetAwaiter() .GetResult();