Skip to content

Commit

Permalink
Merge pull request #40 from marcbachmann/fix-timeout
Browse files Browse the repository at this point in the history
Remove 2 minute force timeout
  • Loading branch information
marcbachmann committed Jun 14, 2015
2 parents e734e9d + bc7d296 commit 65086a1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/pdf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions lib/scripts/pdf_a4_portrait.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@
"type": "git",
"url": "git://github.com/marcbachmann/node-html-pdf.git"
},
"keywords": [
"html",
"pdf",
"phantom",
"phantomjs",
"nodejs"
],
"keywords": ["html", "pdf", "phantom", "phantomjs", "nodejs"],
"bugs": {
"url": "/~https://github.com/marcbachmann/node-html-pdf/issues"
},
Expand Down
3 changes: 2 additions & 1 deletion src/pdf.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = class PDF
@options.phantomPath ?= phantomjs?.path
assert(@options.phantomPath, "html-pdf: Failed to load PhantomJS module. You have to set the path to the PhantomJS binary using 'options.phantomPath'")
assert(typeof @html is 'string' && @html.length, "html-pdf: Can't create a pdf without an html string")
@options.timeout = parseInt(@options.timeout) || 30000


toBuffer: (callback) ->
Expand Down Expand Up @@ -77,7 +78,7 @@ module.exports = class PDF
child.stdin.end()
child.kill()
stderr = [new Buffer('html-pdf: PDF generation timeout. Phantom.js script did not exit.')] unless stderr.length
, parseInt(@options.timeout) || 30000
, @options.timeout

child.stdout.on 'data', (buffer) ->
stdout.push(buffer)
Expand Down
13 changes: 7 additions & 6 deletions src/scripts/pdf_a4_portrait.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ phantom.onError = (msg, trace) ->
exit(buildStack('Script - '+ msg, trace))


# Force cleanup after 2 minutes
setTimeout ->
exit('Force timeout')
, 120000


# Load configurations from stdin
json = JSON.parse(system.stdin.readLine())
exit('Did not receive any html') if !json.html?.trim()
Expand All @@ -43,6 +37,13 @@ page.onError = (msg, trace) ->
exit(buildStack('Evaluation - '+ msg, trace))


# Force cleanup after 2 minutes
timeout = timeout+2000 if timeout = json.options.timeout
setTimeout ->
exit('Force timeout')
, timeout || 12000


# Set up content
# --------------
content = page.evaluate ->
Expand Down

0 comments on commit 65086a1

Please sign in to comment.