Postgres (#30)
* Add postgres * Migrate users * Migrate geneticRequest * Try to fix Concurrent call * Fix asyncawait * Fix async and concurrent * Migrate backtests * Add cache for user by address * Fix backtest migration * Fix not open connection * Fix backtest command error * Fix concurrent * Fix all concurrency * Migrate TradingRepo * Fix scenarios * Migrate statistic repo * Save botbackup * Add settings et moneymanagement * Add bot postgres * fix a bit more backups * Fix bot model * Fix loading backup * Remove cache market for read positions * Add workers to postgre * Fix workers api * Reduce get Accounts for workers * Migrate synth to postgre * Fix backtest saved * Remove mongodb * botservice decorrelation * Fix tradingbot scope call * fix tradingbot * fix concurrent * Fix scope for genetics * Fix account over requesting * Fix bundle backtest worker * fix a lot of things * fix tab backtest * Remove optimized moneymanagement * Add light signal to not use User and too much property * Make money management lighter * insert indicators to awaitable * Migrate add strategies to await * Refactor scenario and indicator retrieval to use asynchronous methods throughout the application * add more async await * Add services * Fix and clean * Fix bot a bit * Fix bot and add message for cooldown * Remove fees * Add script to deploy db * Update dfeeploy script * fix script * Add idempotent script and backup * finish script migration * Fix did user and agent name on start bot
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Common;
|
||||
using Managing.Domain.Workers;
|
||||
using Managing.Infrastructure.Databases.PostgreSql.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Managing.Infrastructure.Databases.PostgreSql;
|
||||
|
||||
public class PostgreSqlWorkerRepository : IWorkerRepository
|
||||
{
|
||||
private readonly ManagingDbContext _context;
|
||||
|
||||
public PostgreSqlWorkerRepository(ManagingDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task DisableWorker(Enums.WorkerType workerType)
|
||||
{
|
||||
var entity = await GetWorkerEntity(workerType);
|
||||
if (entity == null) throw new InvalidOperationException($"Worker with type '{workerType}' not found");
|
||||
entity.IsActive = false;
|
||||
await _context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task EnableWorker(Enums.WorkerType workerType)
|
||||
{
|
||||
var entity = await GetWorkerEntity(workerType);
|
||||
if (entity == null) throw new InvalidOperationException($"Worker with type '{workerType}' not found");
|
||||
entity.IsActive = true;
|
||||
await _context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<Worker> GetWorkerAsync(Enums.WorkerType workerType)
|
||||
{
|
||||
var entity = await GetWorkerEntity(workerType);
|
||||
return PostgreSqlMappers.Map(entity);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Worker>> GetWorkers()
|
||||
{
|
||||
var entities = await _context.Workers.AsNoTracking().ToListAsync().ConfigureAwait(false);
|
||||
return PostgreSqlMappers.Map(entities);
|
||||
}
|
||||
|
||||
public async Task InsertWorker(Worker worker)
|
||||
{
|
||||
var entity = PostgreSqlMappers.Map(worker);
|
||||
await _context.Workers.AddAsync(entity).ConfigureAwait(false);
|
||||
await _context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UpdateWorker(Enums.WorkerType workerType, int executionCount)
|
||||
{
|
||||
var entity = await GetWorkerEntity(workerType);
|
||||
if (entity == null) throw new InvalidOperationException($"Worker with type '{workerType}' not found");
|
||||
entity.ExecutionCount = executionCount;
|
||||
entity.LastRunTime = DateTime.UtcNow;
|
||||
await _context.SaveChangesAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<WorkerEntity?> GetWorkerEntity(Enums.WorkerType workerType)
|
||||
{
|
||||
return await _context.Workers.FirstOrDefaultAsync(w => w.WorkerType == workerType).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user