Skip to content

Commit

Permalink
chore: Add logging when reaching timeout while waiting for file update
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Sep 30, 2024
1 parent 1318a3a commit bde8775
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ private async Task ProcessUpdateFile(UpdateFile message)
return (FileUpdateResult.NoChanges, null);
}

var effectiveUpdate = WaitForFileUpdated(message.FilePath);
var effectiveUpdate = WaitForFileUpdated();
await File.WriteAllTextAsync(message.FilePath, updatedContent);
await effectiveUpdate;

Expand All @@ -533,7 +533,7 @@ private async Task ProcessUpdateFile(UpdateFile message)
this.Log().LogTrace($"Write content: {newText} [{message.RequestId}].");
}

var effectiveUpdate = WaitForFileUpdated(message.FilePath);
var effectiveUpdate = WaitForFileUpdated();
await File.WriteAllTextAsync(message.FilePath, newText);
await effectiveUpdate;

Expand All @@ -552,16 +552,16 @@ private async Task ProcessUpdateFile(UpdateFile message)
return (FileUpdateResult.FileNotFound, $"Requested file '{message.FilePath}' does not exists.");
}

var effectiveUpdate = WaitForFileUpdated(message.FilePath);
var effectiveUpdate = WaitForFileUpdated();
File.Delete(message.FilePath);
await effectiveUpdate;

return (FileUpdateResult.Success, null);
}

static async Task WaitForFileUpdated(string path)
async Task WaitForFileUpdated()
{
var file = new FileInfo(path);
var file = new FileInfo(message.FilePath);
var dir = file.Directory;
while (dir is { Exists: false })
{
Expand All @@ -585,7 +585,11 @@ static async Task WaitForFileUpdated(string path)
};
watcher.EnableRaisingEvents = true;

await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromSeconds(2)));
if (await Task.WhenAny(tcs.Task, Task.Delay(TimeSpan.FromSeconds(2))) != tcs.Task
&& this.Log().IsEnabled(LogLevel.Debug))
{
this.Log().LogDebug($"File update event not received for '{message.FilePath}', continuing anyway [{message.RequestId}].");
}
}
}

Expand Down

0 comments on commit bde8775

Please sign in to comment.