开发者

Running an EventMachine inside of script/runner

开发者 https://www.devze.com 2023-02-05 04:38 出处:网络
I successfully used em-dir-watcher as shown in its example.rb file from the command line, but I found myself needing to开发者_如何学Python call a method from another class and so I opted to go the scr

I successfully used em-dir-watcher as shown in its example.rb file from the command line, but I found myself needing to开发者_如何学Python call a method from another class and so I opted to go the script/runner route instead, invoking rails.

I copy/pasted the example code and placed inside of a self.methodName and encountered this error:

myapp/vendor/rails/railties/lib/commands/runner.rb:48: undefined method `watch' for EventMachine:Module (NoMethodError)

Even if I run something totally simple like:

def self.watcher
    EM.run {
        dw = EMDirWatcher.watch '.' do |paths|
            paths.each do |path|
                puts path
            end
        end
        puts "Monitoring"
    }
end

and invoke script/runner:

script/runner "require 'rubygems'; require 'em-dir-watcher'; Myclass.watcher"

I still get the error. What am I doing wrong?


After spending another day trying to sort through the stack, I've concluded that there's some inherently weird interaction between em-dir-watcher and script/runner. After moving over to another eventmachine-based gem that could do the same task (directory_watcher), everything worked great.

I know that there are performance and feature tradeoffs between the two gems, but for my purposes, I don't notice a difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消