Skip to content

Commit

Permalink
Log error message for the Clockify client
Browse files Browse the repository at this point in the history
  • Loading branch information
eXpl0it3r committed Aug 26, 2023
1 parent 4f5f0d2 commit 0e42e7a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ jobs:
- name: Install Dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
run: dotnet build --configuration Debug --no-restore
- name: Publish
run: dotnet publish --runtime ${{ matrix.platform.rid }} --self-contained --configuration Release -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true
run: dotnet publish --runtime ${{ matrix.platform.rid }} --self-contained --configuration Debug -p:PublishReadyToRun=true -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
Expand Down
27 changes: 21 additions & 6 deletions Clockify/ClockifyContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Clockify.Net;
using Clockify.Net.Models.Projects;
Expand All @@ -13,6 +14,8 @@ public class ClockifyContext
{
private readonly Logger _logger;

private static Mutex _clientAccess = new Mutex();

private ClockifyClient _clockifyClient;
private CurrentUserDto _currentUser = new();

Expand Down Expand Up @@ -51,11 +54,15 @@ public async Task ToggleTimerAsync()
{
return;
}


_clientAccess.WaitOne(1000);
var workspaces = await _clockifyClient.GetWorkspacesAsync();
_clientAccess.ReleaseMutex();

if (!workspaces.IsSuccessful || workspaces.Data is null)
{
_logger.LogWarn("Unable to retrieve available workspaces");
_logger.LogWarn($"Unable to retrieve available workspaces: {workspaces.ErrorMessage}");
_logger.LogWarn($"TT: {_apiKey} / {_serverUrl} / {_workspaceName} / {_clientName} / {_projectName} / {_taskName} / {_timerName} / {_currentUser?.Id}");
return;
}

Expand Down Expand Up @@ -102,10 +109,14 @@ public async Task<TimeEntryDtoImpl> GetRunningTimerAsync()
return null;
}

_clientAccess.WaitOne(1000);
var workspaces = await _clockifyClient.GetWorkspacesAsync();
_clientAccess.ReleaseMutex();

if (!workspaces.IsSuccessful || workspaces.Data is null)
{
_logger.LogWarn("Unable to retrieve available workspaces");
_logger.LogWarn($"Unable to retrieve available workspaces: {workspaces.ErrorMessage}");
_logger.LogWarn($"GRT: {_apiKey} / {_serverUrl} / {_workspaceName} / {_clientName} / {_projectName} / {_taskName} / {_timerName} / {_currentUser?.Id}");
return null;
}

Expand Down Expand Up @@ -180,11 +191,15 @@ private async Task StopRunningTimerAsync()
{
return;
}


_clientAccess.WaitOne(1000);
var workspaces = await _clockifyClient.GetWorkspacesAsync();
_clientAccess.ReleaseMutex();

if (!workspaces.IsSuccessful || workspaces.Data is null)
{
_logger.LogWarn("Unable to retrieve available workspaces");
_logger.LogWarn($"Unable to retrieve available workspaces: {workspaces.ErrorMessage}");
_logger.LogWarn($"SRT: {_apiKey} / {_serverUrl} / {_workspaceName} / {_clientName} / {_projectName} / {_taskName} / {_timerName} / {_currentUser?.Id}");
return;
}

Expand Down Expand Up @@ -214,7 +229,7 @@ private async Task<ProjectDtoImpl> FindMatchingProjectAsync(string workspaceId)
var projects = await _clockifyClient.FindAllProjectsOnWorkspaceAsync(workspaceId, false, _projectName, pageSize: 5000);
if (!projects.IsSuccessful || projects.Data is null)
{
_logger.LogWarn($"Unable to retrieve project {_projectName} on workspace {_workspaceName}");
_logger.LogWarn($"Unable to retrieve project {_projectName} on workspace {_workspaceName}: {projects.ErrorMessage}");
return null;
}

Expand Down

0 comments on commit 0e42e7a

Please sign in to comment.