【发布时间】:2021-09-09 09:28:08
【问题描述】:
我在 Rails 6.1.3.2 中使用带有 sidekiq 适配器的 Active Job
奇怪的是,自定义服务单例方法在 Active Job 中调用时会丢失。
notify_message_event_job.rb
module Chats
class NotifyMessageEventJob < ApplicationJob
queue_as: default
def perform(message:, event:)
Rails.logger.info(PushNotification::Service.name)
Rails.logger.info(PushNotification::Service.singleton_methods.inspect)
PushNotification::Service.create(
user: message.user,
notification: message.content
)
end
end
end
lib/push_notification/service.rb
module PushNotification
class Service
class << self
def create(user:, notification:)
//
end
end
end
end
下面一行:
NotifyMessageEventJob.perform_now(message: message, event: event)
产生以下错误:
[ActiveJob] [Chats::NotifyMessageEventJob] [b1d934c8-afe0-44a0-bc22-44d40eea7d3d] 来自 Sidekiq(默认)的执行 Chats::NotifyMessageEventJob(作业 ID:b1d934c8-afe0-44a0-bc22-44d40eea7d3d)参数:{:message=>#<0x00007fe5bc4f6b00 gid:>0x00007fe5bc4f6b00>
>
标签: ruby-on-rails sidekiq rails-activejob