• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

abatar1 / CyclicalFileWatcher / 15519075363

08 Jun 2025 01:43PM UTC coverage: 55.263% (+1.8%) from 53.509%
15519075363

push

github

abatar1
minor improvements

29 of 66 branches covered (43.94%)

Branch coverage included in aggregate %.

11 of 19 new or added lines in 4 files covered. (57.89%)

2 existing lines in 1 file now uncovered.

160 of 276 relevant lines covered (57.97%)

3.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.93
/src/CyclicalFileWatcher/Internals/FileWatchProcessor.cs
1
using System;
2
using System.Linq;
3
using System.Threading;
4
using System.Threading.Tasks;
5

6
namespace FileWatcher.Internals;
7

8
internal sealed class FileWatchProcessor<TFileStateContent>(
1✔
9
    IFileStateManagerConfiguration configuration,
1✔
10
    IFileSubscriptionTrigger<TFileStateContent> trigger,
1✔
11
    ReadWriteLockProvider lockProvider,
1✔
12
    IFileStateStorageRepository<TFileStateContent> repository)
1✔
13
    where TFileStateContent : IFileStateContent
14
{
15
    public async Task CreateWatchingTask(CancellationToken cancellationToken)
16
    {
17
        while (!cancellationToken.IsCancellationRequested)
15!
18
        {
19
            var tasks = repository.GetAll().Select(async state =>
15✔
20
            {
15✔
21
                using var _ = await lockProvider.AcquireWriterLockAsync(state.Identifier, cancellationToken);
15✔
22
                        
15✔
23
                var file = await TryUpdateFileStateAsync(state, cancellationToken);
15✔
24
                if (file == null)
15✔
25
                    return;
13✔
26
                       
15✔
27
                await TryTriggerSubscriptionAsync(file, cancellationToken);
2✔
28
            });
30✔
29

30
            try
31
            {
32
                await Task.WhenAll(tasks);
15✔
33
            }
15✔
34
            catch (AggregateException e)
×
35
            {
36
                await ProcessFileUpdateExceptionAsync(e);
×
37
                throw;
×
38
            }
39
            finally
40
            {
41
                await Task.Delay(configuration.FileCheckInterval, cancellationToken);
15✔
42
            }
43
        }
44
    }
×
45
    
46
    private async Task<FileState<TFileStateContent>?> TryUpdateFileStateAsync(IFileStateStorage<TFileStateContent> fileStateStorage, CancellationToken cancellationToken)
47
    {
48
        try
49
        {
50
            var fileHasChanged = await fileStateStorage.HasChangedAsync(cancellationToken);
15✔
51
            if (!fileHasChanged)
15✔
52
                return null;
13✔
53
                            
54
            var file = await fileStateStorage.GetLatestAsync(cancellationToken);
2✔
55
            await configuration.ActionOnFileReloaded.Invoke(file.Identifier);
2✔
56
            return file;
2✔
57
        }
58
        catch (Exception e)
×
59
        {
60
            throw new FileWatcherReloadException(fileStateStorage.Identifier, e);
×
61
        }
62
    }
15✔
63
    
64
    private async Task TryTriggerSubscriptionAsync(FileState<TFileStateContent> file, CancellationToken cancellationToken)
65
    {
66
        try
67
        {
68
            await trigger.TriggerSubscriptionsAsync(file, cancellationToken);
2✔
69
            await configuration.ActionOnSubscribeAction.Invoke(file.Identifier);
2✔
70
        }
2✔
71
        catch (Exception e)
×
72
        {
73
            throw new FileWatcherSubscriptionException(file.Identifier, e);
×
74
        }
75
    }
2✔
76
    
77
    private async Task ProcessFileUpdateExceptionAsync(AggregateException e)
78
    {
79
        var exceptions = e.Flatten().InnerExceptions
×
80
            .ToList();
×
81
        foreach (var exception in exceptions)
×
82
        {
83
            switch (exception)
84
            {
85
                case FileWatcherReloadException fileWatcherReloadException:
NEW
86
                    await configuration.ActionOnFileReloadFailed.Invoke(fileWatcherReloadException);
×
NEW
87
                    break;
×
88
                case FileWatcherSubscriptionException fileWatcherSubscriptionException:
NEW
89
                    await configuration.ActionOnSubscribeActionFailed.Invoke(fileWatcherSubscriptionException);
×
90
                    break;
91
            }
92
        }
93
    }
×
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc