1

我有一个我想使用 sidekiq 的 cuba 应用程序。

这就是我设置 config.ru 的方式:

require './app'
require 'sidekiq'
require 'sidekiq/web'

environment = ENV['RACK_ENV'] || "development"
config_vars = YAML.load_file("./config.yml")[environment]

Sidekiq.configure_client do |config|
  config.redis = { :url => config_vars["redis_uri"] }
end

Sidekiq.configure_server do |config|
  config.redis = { url: config_vars["redis_uri"] }
  config.average_scheduled_poll_interval = 5
end

# run Cuba
run Rack::URLMap.new('/' => Cuba, '/sidekiq' => Sidekiq::Web)

我使用 systemd 启动了 sidekiq。这是我从 sidekiq 站点上的 sidekiq.service 改编的 systemd 脚本:

#
# systemd unit file for CentOS 7, Ubuntu 15.04
#
# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Run:
#   - systemctl enable sidekiq
#   - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process.  Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description=sidekiq
# start us only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
After=syslog.target network.target

# See these pages for lots of options:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html
[Service]
Type=simple
Environment=RACK_ENV=development
WorkingDirectory=/media/temp/bandmanage/repos/fall_prediction_verification
# If you use rbenv:
#ExecStart=/bin/bash -lc 'pwd && bundle exec sidekiq -e production'
ExecStart=/home/froy001/.rvm/wrappers/fall_prediction/bundle exec "sidekiq -r app.rb -L log/sidekiq.log -e development"
# If you use the system's ruby:
#ExecStart=/usr/local/bin/bundle exec sidekiq -e production
User=root
Group=root
UMask=0002

# if we crash, restart
RestartSec=1
Restart=on-failure

# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog

# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq

[Install]
WantedBy=multi-user.target

调用工人的代码是:

 raw_msg = JSON.parse(req.body.read, {:symbolize_names => true})
          if raw_msg
            ts = raw_msg[:ts]
            waiting_period = (1000*60*3) # wait 3 min before checking
            perform_at_time = Time.at((ts + waiting_period)/1000).utc

            FallVerificationWorker.perform_at((0.5).minute.from_now, raw_msg)

            my_res = { result: "success", status: 200}.to_json
            res.status = 200
            res.write my_res
          else
            my_res = { result: "not found", status: 404}.to_json
            res.status = 404
            res.write my_res
          end

我只使用默认的 q。

我的问题是根本没有处理这项工作。

4

1 回答 1

4

在您运行systemctl enable sidekiq它以使其在启动时启动并systemctl start sidekiq立即启动后,您应该有一些日志可供查看,这些日志将提供有关任何启动失败的一些详细信息:

 sudo journalctl -u sidekiq

查看日志,查看 systemd 文档并根据需要调整您的单元文件。您可以找到所有已安装的 systemd 文档apropos systemd。要查看的一些最有用的手册页是systemd.servicesystemd.execsystemd.unit

于 2016-10-03T15:20:44.943 回答