Rails 7项目运行Resque报错:Unsupported command argument type: Resque::Worker
Rails 7 启动Resque Worker失败报错解决方案
问题描述
在本地Rails 7项目中执行命令QUEUE=* bundle exec rake resque:work启动Resque Worker时失败,报错信息如下:
rake aborted! TypeError: Unsupported command argument type: Resque::Worker Original Exception (TypeError): Unsupported command argument type: Resque::Worker Original Exception (Resque::PruneDeadWorkerDirtyExit): Worker Davids-Mac-mini:38378:* did not gracefully exit while processing <Unknown Job>
已确认redis-server处于正常运行状态。
项目配置信息
application.rb
config.active_job.queue_adapter = :resque
config/initializers/resque.rb
require 'resque/server' if Rails.env.development? Resque.redis = Redis.new(host: 'localhost', port: '6379') else uri = URI.parse(ENV['REDIS_URL']) REDIS = Redis.new(host: uri.host, port: uri.port, password: uri.password) Resque.redis = REDIS end
application_job.rb
class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError end
schedules_job.rb
class SchedulesJob < ApplicationJob queue_as :default def perform(id) puts 'Hello world!' end end
Rakefile
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require_relative 'config/application' require 'resque' require 'resque/tasks' task 'resque:setup' => :environment Rails.application.load_tasks
解决步骤
清理Redis中的死Worker记录
终端执行redis-cli进入Redis命令行,执行以下命令删除残留的死Worker记录:DEL resque:workers该操作可解决
Resque::PruneDeadWorkerDirtyExit报错。适配Resque与Redis gem版本
Rails 7对依赖版本兼容性要求严格,在Gemfile中指定兼容的版本:gem 'resque', '~> 2.2' gem 'redis', '~> 4.8'执行
bundle update resque redis更新依赖包。优化Resque初始化配置
修改config/initializers/resque.rb,简化Redis连接配置(Redis支持直接传入URI对象):require 'resque/server' Resque.redis = if Rails.env.development? Redis.new(host: 'localhost', port: 6379) else Redis.new(URI.parse(ENV['REDIS_URL'])) end重新启动Worker
执行以下命令重启Resque Worker:QUEUE=* bundle exec rake resque:work若仍有问题,可尝试直接使用Resque命令启动:
bundle exec resque work QUEUE=*
内容的提问来源于stack exchange,提问作者David Cantu
相关产品推荐
相关产品推荐

