-
-
Notifications
You must be signed in to change notification settings - Fork 660
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
Alternative interface for the AsyncFtpFolderMonitor #1663
Alternative interface for the AsyncFtpFolderMonitor #1663
Conversation
The failed checks is for code I didn't touch. |
Thanks for this huge update. QuestionHowever I don't understand why you are using the async version, then adding a while loop to essentially turn it into a fully synchronous program. In my understanding async methods should never be blocking (they should never contain perpetual while loops). Why not just use the sync version then? Wouldnt this "alternate interface" be better addressed by simply disabling the timer feature on the existing sync
This usage indicates a blocking synchronous program, so I have no idea why async is used. You appear to be jumping through hoops just to get a simple cancellable while loop. What does this accomplish? What are the advantages of using async in this manner? ChangesCan you please make the following changes if you wish for me to merge this.
|
It is not blocking, its async. Caller can just skip
or if you want automatic restart on error
I think this is the best way to handle errors from the monitor or from events. The current version just do It also avoids the nasty race condition when Your other points are valid even if I find two polling rates easier to understand (why does is it sometimes take ~15 minutes before I see new file if I have polling set to 10 minutes?) but it is not important. |
That is a bad idea. Multiple handlers can still be added with e.g. If only one handler should be allowed, a method call |
See, I would still like just one event handler to be allowed and not multiple.
I will await your changes before I can merge it. |
Thanks for these amendments. @robinrodricks will review this as his schedule allows. |
Restored the previous code and reworked it into a new class instead. Don't think it should be merged as is but use it more as something to discuss. Summary of changes:
|
Make sure you pick up #1668 to keep the code up to current master. Or we force push or something. |
split PollFolder to reduce cyclomatic complexity. comments/example cleanup
Don't worry too much about Codacity - it's a PITA. Robin will be back soon and then this can be taken forward. |
I'm normally very happy to receive every contribution and PR as I believe our contributors have been very instrumental in our success. This PR however, had many points that irked me and did not go the way I wanted. So I was forced to change it myself. Changes that I made
Naming@adrianm64 Can you suggest a better name for your async monitor. I'm not happy with "blocking async monitor" as I do not think it reflects its behaviour correctly. As you are the original author, I'm giving you a chance to suggest a better name. |
Sorry about that. I made the class in a way that I can use in my day work and your version still qualifies for that. I build 30-40 different integrations between various business systems a year and maybe 30% of them use polling ftp/ftps/sftp in one end. I would not use the regular monitor classes because:
Some small things:
I will probably do a new PR with better examples and documentation. |
Alright.
Good to know.
You could enhance them in a PR.
This is a good idea. |
Released. https://www.nuget.org/packages/FluentFTP/52.0.0 FTP monitors are now documented here. https://github.com/robinrodricks/FluentFTP/wiki/FTPS-Monitor |
This PR contains an alternative interface for the AsyncFtpFolderMonitor.
Changes:
StartAsync
and runs until the supplied CancellationToken is set or an exception occurs.This means you can add your own error handling and avoid a race condition on stop
Unfortunately it means method calls to register event instead of
+=
.(async events can optionally have a CancellationToken argument)
Multiple events are called in sequence, i.e. not parallel
Shorter delay between a new file is detected and event is called when
WaitTillFileFullyUploaded
is true;Intervals expressed in TimeSpan
ChangeDetected gets a list of all added/changed/deleted filenames.
Pass the FtpClient to the events. Your event probably want to do something with the files.
Complete console application