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

Ruby 3.1.1升级后Rails+Google Cloud Task出现ArgumentError求助

解决Ruby 3.1.1下Cloudtasker部署GCP任务报错的问题

问题根源

Ruby 3.1对类型处理做了更严格的校验,而cloudtasker 0.13.0版本未适配这种变化——它默认传递的整数超时时间(600秒)无法被GCP Tasks API识别,API要求参数必须是Hash或Google::Protobuf::Duration类型,因此触发ArgumentError。

解决方案

1. 优先升级Cloudtasker到兼容版本

cloudtasker 0.14.0及以上版本已经修复了Ruby 3.1的兼容性问题,直接升级即可解决:

bundle update cloudtasker

升级后重新部署服务,验证任务执行情况。

2. 手动修改超时参数格式(无法升级时)

如果暂时不能升级cloudtasker,把默认的整数超时改成Hash格式,让GCP API能正确解析:

全局配置修改

在config/initializers/cloudtasker.rb中调整超时配置:

Cloudtasker.configure do |config|
  # 替换原来的 config.timeout = 600
  config.timeout = { seconds: 600 }
end

单个Worker配置修改

也可以在你的EnrollmentsValidatorWorker中单独指定:

class EnrollmentsValidatorWorker
  include Cloudtasker::Worker
  cloudtasker_options queue: :enrollments, lock: :while_executing, on_conflict: :reject, timeout: { seconds: 600 }

  def perform
    EnrollmentsValidationByItDataset.call
  rescue StandardError => e
    send_message "Error: #{e.message}. #{e.backtrace.join("\n")}"
  end
end

3. 同步升级Google Cloud Tasks依赖

确保google-cloud-tasks gem版本适配Ruby 3.1,建议升级到2.0.0以上:

bundle update google-cloud-tasks

内容的提问来源于stack exchange,提问作者Arnaldo Díaz Molina

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 06:53:22