Skip to content

Commit

Permalink
Switch to using the listen gem for Mac OSX support
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 7, 2020
1 parent 60d2f2a commit 456eb20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ gem "inifile", "~>3.0", :require => false
gem "inventory_refresh", "~>0.2.0", :require => false
gem "kubeclient", "~>4.0", :require => false # For scaling pods at runtime
gem "linux_admin", "~>2.0", ">=2.0.1", :require => false
gem "listen", "~>3.2", :require => false
gem "log_decorator", "~>0.1", :require => false
gem "manageiq-api-client", "~>0.3.4", :require => false
gem "manageiq-loggers", "~>0.5.0", :require => false
Expand All @@ -68,7 +69,6 @@ gem "query_relation", "~>0.1.0", :require => false
gem "rails", "~>5.2.4", ">=5.2.4.4"
gem "rails-i18n", "~>5.x"
gem "rake", ">=12.3.3", :require => false
gem "rb-inotify", "~>0.10.0", :require => false
gem "rest-client", "~>2.1.0", :require => false
gem "ripper_ruby_parser", "~>1.5.1", :require => false
gem "ruby-progressbar", "~>1.7.0", :require => false
Expand Down
27 changes: 13 additions & 14 deletions lib/ansible/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,28 +363,27 @@ def pid_file(base_dir)
end

def wait_for(path)
require "rb-inotify"
require "listen"
require "concurrent"

dir_name = File.dirname(path)
file_name = File.basename(path)

path_created = Concurrent::Event.new

notifier = INotify::Notifier.new
notifier.watch(dir_name, :moved_to, :create) do |event|
# Once the file we are looking for is created set the concurrent event
path_created.set if event.name == file_name
listener = Listen.to(dir_name, :only => %r{\A#{file_name}\z}) do |modified, added, _removed|
path_created.set if added.include?(path) || modified.include?(path)
end

thread = Thread.new { notifier.run }

res = yield

# Wait for the target file to exist
path_created.wait
thread = Thread.new { listener.start }

# Shutdown the inotify loop and join the thread
notifier.close
thread.join
begin
res = yield
path_created.wait
ensure
listener.stop
thread.join
end

res
end
Expand Down

0 comments on commit 456eb20

Please sign in to comment.