gpt4 book ai didi

ruby-on-rails - 延迟作业反序列化错误,无法加载 : allocator undefined for Proc

转载 作者:数据小太阳 更新时间:2023-10-29 08:00:07 24 4
gpt4 key购买 nike

使用 delayed_job_active_record gem 第 4 版,我想延迟对外部 API 的请求。我的工作被添加到数据库中,rake jobs:work 运行它并将其从数据库中删除。但是,我的 messages_controller.rb 中的实际延迟代码从未执行过。

如果我尝试在 Rails 控制台中执行 Delayed::Job.last.invoke_job,我会收到以下错误:

Delayed::DeserializationError: Job failed to load: allocator undefined for Proc. Handler: "--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:MyApp::Zendesk\n  client: !ruby/object:ZendeskAPI::Client\n    config: !ruby/object:ZendeskAPI::Configuration\n      client_options: {}\n      cache: !ruby/object:ZendeskAPI::LRUCache\n        size: 1000\n        store: {}\n        lru: []\n      url: https://redacted.zendesk.com/api/v2\n      username: redacted\n      password: redacted\n      retry: true\n      logger: !ruby/object:Logger\n        progname: \n        level: 0\n        default_formatter: !ruby/object:Logger::Formatter\n          datetime_format: \n        formatter: \n        logdev: !ruby/object:Logger::LogDevice\n          shift_size: \n          shift_age: \n          filename: \n          dev: !ruby/object:IO {}\n          mutex: !ruby/object:Logger::LogDevice::LogDeviceMutex\n            mon_owner: \n            mon_count: 0\n            mon_mutex: !ruby/object:Mutex {}\n    callbacks:\n    - !ruby/object:Proc {}\n    resource_cache: {}\nmethod_name: :create_support_ticket\nargs:\n- !ruby/hash:ActionController::Parameters\n  name: redacted\n  email: redacted\n  reason: General\n  message: test\n"

尝试运行的代码是 create_support_ticket 方法:

# messages_controller.rb
require 'zendesk'

class MessagesController < ApplicationController
layout "application"

# /suport/contact-us
def contact_us
zendesk = MyApp::Zendesk.new
zendesk.delay.create_support_ticket(params[:message])

# render page
respond_to do |format|
flash[:notice] = "Email sent successfully!" if @sent
format.html { render "pages/support/contact-us" }
end
end
end

# zendesk.rb
require 'zendesk_api'

module MyApp
class Zendesk
attr_accessor :client

def initialize(*args)
@client = create_client
end

# contact-us ticket methods
def create_support_ticket(params={})
unless params.blank? || @client.blank?
# get or create user_id for submitter
params[:requester_id] = check_user_exists(params)

begin
ticket = @client.tickets.create(
subject: "Support Ticket",
comment: { value: params[:message] },
submitter_id: params[:requester_id],
requester_id: params[:requester_id],
assignee_id: 201578811,
status: "new",
fields: [
{id: 20887016, value: "Support"},
{id: 20966436, value: "New"}])
return ticket
rescue => e
Airbrake.notify e
end
else
return false
end
end
end
end

最佳答案

DelayedJob 尝试序列化您调用方法的对象。

在您的例子中,该对象有一个 IO 和一个 Proc 对象。它们都与序列化不兼容。您能做的最好的事情就是编写一个简单的包装器,它没有依赖项并初始化方法调用中的所有内容。

关于ruby-on-rails - 延迟作业反序列化错误,无法加载 : allocator undefined for Proc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20733076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com