Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 1.4 - FileObserver and FileStream not working as expected on .net core / MAC #298

Open
BillBaird opened this issue Sep 5, 2019 · 1 comment

Comments

@BillBaird
Copy link

This is not an AKKA issue, but it is an issue that causes 1.4 (adding FileObserver/FileStream) not to work with .net core and/or on a MAC.

I ran into two issues. The first was that in order to get the file change notifications, I had to modify the SystemFileWatcher construction in FileObserver.Start() to use a filter of "*", rather than _fileNameOnly. Once I made this change, the OnFileChanged method was properly called. To verify, I changed it back and the OnFileChanged was not called. So, I changed initialization of _watcher to
_watcher = new FileSystemWatcher(_fileDir, "*")

The second issue is that when the TailActor.OnReceive method properly received a FileWrite message, the FileStreamReader always returned an empty string. Even though the SystemFileWatcher was properly seeing the change to the file, the FileStreamReader was not realizing the file size had increased and therefore .ReadToEnd was returning an empty string. A hack workaround was to remember the previous file length, and then close and reopen the FileStream and FileStreamReader each time. That worked, and allowed the modified text to be picked up and properly displayed. Obviously this is not the best way of handling this, but it did allow the Tail to produce the desired output. Of course this caused problems for lesson 1.6.

Lastly, to truly provide "Tail" behavior, you may want to change the ConsoleWriterActor's Console.WriteLine(message) (in the last "else" of the OnReceive) to simply a Console.Write(message) as this allows the output to precisely echo the file input.

As I said, none of what I point out is AKKA.net related, but with the increased popularity of .net core, including developing on a MAC, having a lesson which works as expected allows the student to focus on learning AKKA, and not battling environmental differences from the bootcamp lessons that were built on the original .net framework, likely in Windows.

@berryware
Copy link

I got this to work on my Mac without modifications, by using echo to update the file. e.g.
echo "more cowbell" >> sample_log_file.txt
this will get captured and displayed in the terminal window.

Using textedit.app does not work as it saves to a tmp file. And if you tail a file already opened by textedit, the updates do not seem to come through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants