Skip to content

Commit

Permalink
increment and decrement users count
Browse files Browse the repository at this point in the history
  • Loading branch information
granstel committed Mar 14, 2024
1 parent 50d1277 commit 208c181
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Dodo1000Bot.Services/Metrics/MetricsCollector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ public static void Set(string key, double value)
{
Metrics.WithLabels(key).Set(value);
}

public static void Decrement(string key)
{
Metrics.WithLabels(key).Dec();
}
}
9 changes: 7 additions & 2 deletions Dodo1000Bot.Services/UsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public async Task SaveAndNotify(User user, CancellationToken cancellationToken)
{
await _usersRepository.SaveUser(user, cancellationToken);

MetricsCollector.Increment("users");

await CheckAndNotifyAboutSubscribers(cancellationToken);
}

Expand Down Expand Up @@ -62,8 +64,11 @@ internal async Task CheckAndNotifyAboutSubscribers(CancellationToken cancellatio
}
}

public Task Delete(User user, CancellationToken cancellationToken) =>
_usersRepository.Delete(user, cancellationToken);
public async Task Delete(User user, CancellationToken cancellationToken)
{
await _usersRepository.Delete(user, cancellationToken);
MetricsCollector.Decrement("users");
}

public Task<IList<User>> GetUsers(Source messengerType, CancellationToken cancellationToken) =>
_usersRepository.GetUsers(messengerType, cancellationToken);
Expand Down

0 comments on commit 208c181

Please sign in to comment.