我使用 Kamal 部署 Sinatra Web 应用程序,并在其中使用 Grover 处理 pdf。我遇到的问题是,当我访问 https://myserver.com/pdf3 时,出现以下错误;
Grover::JavaScript::TimeoutError at /pdf3
Navigation timeout of 30000 ms exceeded
这是我的路线,
get "/up" do
"UP"
end
get '/pdf2' do # Works
grover = Grover.new("https://www.google.com")
content_type 'application/pdf'
attachment 'output.pdf'
grover.to_pdf
end
get '/pdf3' do # Timeout error
grover = Grover.new("https://myserver.com/up")
content_type 'application/pdf'
attachment 'output.pdf'
grover.to_pdf
end
如果我调用 http://myserver.com/pdf2 那么 grover 就会工作并将谷歌网站放入 PDF 中并将其发送到我的浏览器。我希望能够调用自身,但它似乎在超时时挂起该进程和所有其他进程。
我还使用具有以下设置的 nginx 代理;
server {
server_name myserver.com;
limit_rate 50k;
access_log off;
location / {
proxy_pass http://127.0.0.1:8081;
}
}
我的 Dockerfile
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=2.7.8
FROM ruby:$RUBY_VERSION-slim as base
# Rails app lives here
WORKDIR /sinatra
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential ruby-dev libmagick++-dev curl \
ssh software-properties-common npm
RUN npm install npm@latest -g && \
npm install n -g && \
n latest
RUN apt-get install -y wget
RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
COPY . /sinatra
RUN bundle install
RUN npm install
ENV GROVER_NO_SANDBOX="true"
ENV DISABLE_JEMALLOC="true"
# ENV RACK_ENV="production"
EXPOSE 4567
CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "-p", "4567"]
我的deploy.yml
# Name of your application. Used to uniquely configure containers.
service: myserver
# Share the users directory for SSH key use
volumes:
- "/home/map7:/home/map7"
# Name of the container image.
image: map7/myserver
# Deploy to these servers.
servers:
- 11.111.111.111
# Credentials for your image host.
registry:
# Specify the registry server, if you're not using Docker Hub
# server: registry.digitalocean.com / ghcr.io / ...
username: myuser
# Always use an access token rather than real password when possible.
password:
- KAMAL_REGISTRY_PASSWORD
# Inject ENV variables into containers (secrets come from .env).
# Remember to run `kamal env push` after making changes!
env:
secret:
- REPORTS_USER
- REPORTS_PASS
# Configure builder setup.
builder:
multiarch: false
# Configure custom arguments for Traefik. Be sure to reboot traefik when you modify it.
traefik:
host_port: "127.0.0.1:8081"
options:
cpus: 2
# Configure a custom healthcheck (default is /up on port 3000)
healthcheck:
path: /healthz
port: 4567
就像一次只有一个进程在运行,并且通过路由 /pdf3 我正在调用嵌套在其中的同一服务器。我该如何解决这个问题?
我设法通过从默认的“瘦”服务器切换为使用“puma”来解决此问题。
添加 puma GEM
Dockerfile:切换到 puma
CMD ["bundle", "exec", "puma", "-b", "tcp://0.0.0.0", "-p", "4567"]
承诺
部署
kamal deploy
Thin 一次仅接受一个连接,而 puma 默认情况下允许多个连接。