Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid conflict with Phantomjs class. Closes #4.
- Loading branch information
Showing
3 changed files
with
24 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
require 'timeout' | ||
|
||
class Phantomjs | ||
attr_accessor :timeout | ||
module Indexable | ||
class Phantomjs | ||
attr_accessor :timeout | ||
|
||
def initialize(script, *args) | ||
@script = script | ||
@args = args | ||
@timeout = 20 | ||
end | ||
def initialize(script, *args) | ||
@script = script | ||
@args = args | ||
@timeout = 20 | ||
end | ||
|
||
def run | ||
pipe = nil | ||
begin | ||
Timeout.timeout(@timeout) do | ||
pipe = IO.popen(["phantomjs", @script] + @args) | ||
def run | ||
pipe = nil | ||
begin | ||
Timeout.timeout(@timeout) do | ||
pipe = IO.popen(["phantomjs", @script] + @args) | ||
Process.wait pipe.pid | ||
return pipe.read | ||
end | ||
rescue Timeout::Error | ||
Process.kill 9, pipe.pid | ||
Process.wait pipe.pid | ||
return pipe.read | ||
return "Couldn't render page... orz." | ||
end | ||
rescue Timeout::Error | ||
Process.kill 9, pipe.pid | ||
Process.wait pipe.pid | ||
return "Couldn't render page... orz." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters