Пример #1
0
        public GitVersionedConfigProvider(IGitApi git, string repository, string path, string branch, TimeSpan ttl, TimeSpan invalidTtl)
        {
            _git        = git ?? throw new NullReferenceException(nameof(git));
            _ttl        = ttl;
            _invalidTtl = invalidTtl;

            _gitQuery = new GitQuery(repository, path, branch);
            _current  = TimedEntry.Create(VersionConfig.Fail(new InvalidOperationException()), TimeSpan.Zero);
        }
Пример #2
0
        private TimedEntry <VersionedConfig> ReadData()
        {
            VersionedConfig vc;

            try
            {
                //as all infrastructure is sync
                var gitItem = _git.GetFile(_gitQuery).ConfigureAwait(false).GetAwaiter().GetResult();
                vc = new VersionedConfig(gitItem);
            }
            catch (Exception ex)
            {
                return(TimedEntry.Create(VersionConfig.Fail(ex), _invalidTtl));
            }
            return(TimedEntry.Create(vc, _ttl));
        }
Пример #3
0
        public VersionedConfig GetConfig()
        {
            if (_current.IsValid)
            {
                return(_current.Value);
            }

            if (Interlocked.CompareExchange(ref _loading, 1, 0) == 0)
            {
                var updated = ReadData();
                if (updated.Value.LastError == null)
                {
                    _current = updated;
                    Interlocked.Decrement(ref _loading);
                    return(_current.Value);
                }
                Interlocked.Decrement(ref _loading);
            }

            return(_current.Value);
        }