【发布时间】:2020-08-13 01:42:45
【问题描述】:
我似乎有一个与Rufus-Scheduler Running Only Once 非常相似的问题,但我不太明白建议的重构,我们使用 puma。谷歌搜索产生了一些非常古老的结果。
我正在尝试使用 rufus-scheduler 执行 Rake 任务。它执行一次,然后不再执行。
我的调度程序文件看起来像
require 'rufus-scheduler'
require 'rake'
Rails.app_class.load_tasks
scheduler = Rufus::Scheduler.singleton
scheduler.every '2m' do
# scheduler.cron('0 08 * * 6') do
begin
Rake::Task['load_organizations'].invoke
rescue Exception => e
Rails.logger.error 'ERROR in load_organizations'
Rails.logger.error e.inspect
Rails.logger.error e.backtrace
end
end
我的日志是这样开始的:
bash -c "RBENV_VERSION=2.5.5 /usr/local/bin/rbenv exec ruby /Users/.../bin/rails server -b 0.0.0.0 -p 3000 -e development"
=> Booting Puma
=> Rails 5.2.4 application starting in development
=> Run `rails server -h` for more startup options
* Starting metrics server on tcp://0.0.0.0:3030
Puma starting in single mode...
* Version 3.12.2 (ruby 2.5.5-p157), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Load organizations from github ### the task is executed once
不是 puma 专家,这是配置:
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
plugin :metrics
根据措辞,我尝试了scheduler = Rufus::Scheduler.singleton(:max_work_threads => 5),但没有任何效果。另外,尝试添加scheduler.join,但这会使启动挂起并仅打印
bash -c "RBENV_VERSION=2.5.5 /usr/local/bin/rbenv exec ruby /Users/.../bin/rails server -b 0.0.0.0 -p 3000 -e development"
=> Booting Puma
=> Rails 5.2.4 application starting in development
=> Run `rails server -h` for more startup options
彪马 3.12.2 rufus-scheduler-3.6.0 导轨-5.2.4 红宝石-2.5.5-p157 macOS 10.14.6
【问题讨论】:
-
“空话”是什么意思?
标签: ruby-on-rails puma rufus-scheduler