[英]rufus-scheduler executes rake task only once with puma
我似乎有一個與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
puma 3.12.2 rufus-scheduler-3.6.0 rails-5.2.4 ruby-2.5.5-p157 macOS 10.14.6
我是大多數你認為“廢話”的作者。 我將通過回答您的問題來增加這堆冗長的措辭。
事實上,我通過創建一個更簡單的項目版本進行了仔細檢查。 它在
https://github.com/jmettraux/sof63386937
您遇到的不是 rufus-scheduler 問題。 只是你誤解了瑞克。
讓Rake配合的方法:
scheduler.every '2m' do
# scheduler.cron('0 08 * * 6') do
begin
Rake::Task['load_organizations'].invoke
Rake::Task['load_organizations'].reenable # <------------ ADD THIS
rescue Exception => e
Rails.logger.error 'ERROR in load_organizations'
Rails.logger.error e.inspect
Rails.logger.error e.backtrace
end
end
閱讀本文可能會有所幫助:
https://til.hashrocket.com/posts/4897ed42b7-invoking-rake-tasks-multiple-times
享受。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.