-
Notifications
You must be signed in to change notification settings - Fork 247
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
TCP forwarding #139
TCP forwarding #139
Conversation
The |
TCP::Listener.new(target, :broadcaster, *args, &block) | ||
else | ||
Listener.new(*args, &block) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of using another method for forwarding, maybe something like Listen.for(target, 'dir_path')
or Listen.to_forward
...
I don't really like this big if in the to method, or maybe move it to another _listener_class
private method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From an aesthetic perspective I like how Listen.to 'foo', forward_to: '10.0.0.1'
flows, as well as Listen.on '10.0.0.1:4000'
, but I agree on the current implementation being rather hacky and far from ideal.
What would the _listener_class
private method you had in mind look like?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmm after some more thinking and because how TCP::Listener is different to initialize than Listener, _listener_class
idea seems not so good anymore. :(
I agree than Listen.to('foo', forward_to: '10.0.0.1')
is quite straightforward. So don't touch it for now. Thanks!
Please rebase from master, I have fixed the specs on Travis. :) |
Overall I really like the coding style, thanks for this awesome PR. CodeClimate will like it! I'll give it a try in the next days. |
I have test it locally with: broadcaster.rb: require 'listen'
listener = Listen.to(Dir.pwd, forward_to: '127.0.0.1:4000')
listener.start
sleep receiver.rb require 'listen'
listener = Listen.on('127.0.0.1:4000') do |modified, added, removed|
puts "-----------"
puts "modified: #{modified}"
puts "added: #{added}"
puts "removed: #{removed}"
end
listener.start
sleep A problem is that first modification is always detected as an addition because receiver.rb isn't able to build a record on start. The solution is to give the responsibility of change type (modified, added or removed) detection on the broadcaster side and sent change with it. Makes sense? |
Changes Unknown when pulling a0afe4f on timkurvers:feature/tcp-forwarding into * on guard:master*. |
Changes Unknown when pulling e3a8a97 on timkurvers:feature/tcp-forwarding into * on guard:master*. |
@thibaudgg I seem to get the first modification detected as addition even on master or on the TCP broadcaster, not just the TCP recipient. Can you confirm that? Regardless, your assessment of the TCP receiver not handling this correctly is accurate, so I'll look into that. Any idea what is up with the |
Changes Unknown when pulling f5d4328 on timkurvers:feature/tcp-forwarding into * on guard:master*. |
Changes Unknown when pulling 00d0c77 on timkurvers:feature/tcp-forwarding into * on guard:master*. |
@timkurvers for me, on OS X with darwin and polling adapter, first detection is detected as modification. On which platform are you? It seems you manage to fix require 'listen'
listener = Listen.to(Dir.pwd) do |modified, added, removed|
puts "-----------"
puts "modified: #{modified}"
puts "added: #{added}"
puts "removed: #{removed}"
end
listener.start
sleep |
On OSX here as well. When listening to directories that are not the current working directory I seem to get the issue: require 'listen'
listener = Listen.to 'lib' do |*args|
p args
end
listener.start
sleep $ touch lib/listen.rb
With the polling adapter however, that does not occur: require 'listen'
listener = Listen.to 'lib', force_polling: true do |*args|
p args
end
listener.start
sleep $ touch lib/listen.rb
The |
Mmm, I'm not able to reproduce it even using an external directory, what kind of hard drive do you have (SSD here)? Please try to wait some time before touching the file to see if it change anything. Where are you seeing The |
On an SSD here, too. I tried waiting a bit but that didn't change anything. I'm running the examples from within The |
I launch it from a ruby file with Ok I see the errors message, I think we can skip it for now... |
Have tried it with the following #!/usr/bin/env ruby
require 'listen'
listener = Listen.to 'lib', 'spec', debug: true do |*args|
p args
end
listener.start
sleep The first file added, modified or removed in each of those directories seem to fire of additions. Anything that would help debugging this? Gemfile.lock? |
Ok nice, I was able to reproduce it. It's only happen when directory aren't given with absolute path. I'll fix it, thanks! |
Fixed in 146b5cd, could you rebase and give it a try please? Thanks! |
Excellent, works fine! I can also confirm the TCP receiver correctly relies on the broadcasted changes. |
Great news, I just released Listen 2.0.0, so this feature will be added in 2.1.0. |
Yep! I will most probably need some help with speccing threaded/Celluloid'd code though. |
Sure, feel free to ask for help. |
Nice work. Cant wait to see it merged! |
If someone wants to actually try this here's a simple way to build it into guard: https://github.com/johannesbecker/guard/commit/a9c14b514ffd4c64b97ffd8188e5f197f095ada1 Additionally you need to rebase this PR on Listen 2.2 - did so at https://github.com/johannesbecker/listen Works like a charm 👍 |
Thanks for giving this a go @JohannesBecker, much appreciated! I have gotten a bit side-tracked with other projects but hope to be able to spec the PR soonish. |
Great can't wait to merge it! |
@JohannesBecker once merged, it would be great if you could submit your branch to Guard via a PR, thanks! |
The message implementation now uses JSON. Wasn't really sure where to document TCP forwarding in the README but I felt it was much less of a core feature than the adapters, so it's beneath those. If anything needs to be amended please let me know :) |
Awesome, @timkurvers thanks a lot for your great work! 2.5.0 released! |
@timkurvers @thibaudgg thank you for this, it's going to be a major improvement to our workflow. |
Wooo, thanks for merging! |
Thank you. Thank you! I had taken a stab at this almost a year ago and it defeated me in the time I had. Kudos! So, can we use this with https://github.com/ideasasylum/guard#-o--listen_on-option I think I need a better host 'listener' script though as it can't be killed from the console |
@ideasasylum great, please submit a PR on Guard. I would be greatly happy to merge it! |
@thibaudgg done: guard/guard#555 |
@ideasasylum thanks we'll continue the discussion there. (Tomorrow I think) |
Initial implementation for broadcasting and receiving file system modifications over TCP, as discussed in #57.