using PARR.AIHITRelationshipsSyncer;

namespace PARR.AIHITRelationshipsSyncerWorker;

public class Worker : BackgroundService
{
    private readonly IServiceProvider serviceProvider;

    public Worker(IServiceProvider serviceProvider)
    {
        this.serviceProvider = serviceProvider;
    }


    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        using (var scope = serviceProvider.CreateScope())
        {
            var relationshipsSyncer = scope.ServiceProvider.GetService<IRelationshipsSyncer>();

            if (relationshipsSyncer == null)
                throw new Exception($"Не смог получить серивс {nameof(IRelationshipsSyncer)}");

            await relationshipsSyncer.StartAsync();
        }
    }
}
