You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

解决步骤

  1. 清理Redis中的死Worker记录
    终端执行redis-cli进入Redis命令行,执行以下命令删除残留的死Worker记录:

    DEL resque:workers
    

    该操作可解决Resque::PruneDeadWorkerDirtyExit报错。

  2. 适配Resque与Redis gem版本
    Rails 7对依赖版本兼容性要求严格,在Gemfile中指定兼容的版本:

    gem 'resque', '~> 2.2'
    gem 'redis', '~> 4.8'
    

    执行bundle update resque redis更新依赖包。

  3. 优化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
    
  4. 重新启动Worker
    执行以下命令重启Resque Worker:

    QUEUE=* bundle exec rake resque:work
    

    若仍有问题,可尝试直接使用Resque命令启动:

    bundle exec resque work QUEUE=*
    

内容的提问来源于stack exchange,提问作者David Cantu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:54:26