mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServer.Services;
|
|
using BTCPayServer.Services.Rates;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
namespace BTCPayServer.HostedServices
|
|
{
|
|
public class RatesHostedService : IHostedService
|
|
{
|
|
private SettingsRepository _SettingsRepository;
|
|
private BTCPayRateProviderFactory _RateProviderFactory;
|
|
public RatesHostedService(SettingsRepository repo, IRateProviderFactory rateProviderFactory)
|
|
{
|
|
this._SettingsRepository = repo;
|
|
_RateProviderFactory = rateProviderFactory as BTCPayRateProviderFactory;
|
|
}
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
if (_RateProviderFactory == null)
|
|
return;
|
|
var rates = (await _SettingsRepository.GetSettingAsync<RatesSetting>()) ?? new RatesSetting();
|
|
_RateProviderFactory.CacheSpan = TimeSpan.FromMinutes(rates.CacheInMinutes);
|
|
}
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|