Sidekiq - Sinatra - 无法从我的ActiveRecord对象中读取

时间:2016-08-16 03:49:15

标签: ruby activerecord sinatra sidekiq sinatra-activerecord

出于某种原因,我的sidekiq工作人员无法读取我的ActiveRecord模型。这是我的工人班。它在尝试从我的User对象中读取时失败:name = User.find_by(id: user_id).first_name

require 'gcm'

module Socio
    class RequestNotificationWorker
        include Sidekiq::Worker
        sidekiq_options retry: false

        def perform(target_token, key)
            begin
                gcm = GCM.new(key)
                registration_ids= [target_token]
                options = {notification: {title: "Connection request!", body: "You have a new Socio request.",
                                          sound: "default", badge: 1, type: "1"},
                           collapse_key: "New Connections", content_available: true,  priority: "high"}
                gcm.send(registration_ids, options)
                {success: true}
            rescue => e
                {success: false, error: e.to_s}
            end
        end
    end

    class ConfirmNotificationWorker
        include Sidekiq::Worker
        sidekiq_options retry: false

        def perform(target_token, key)
            begin
                gcm = GCM.new(key)
                name = User.find_by(id: @user_id).first_name
                registration_ids= [target_token]
                options = {notification: {title: "Connection Confirmed!", body: "#{name} has accepted your Socio request.",
                                          sound: "default", badge: 1, type: "2"},
                           collapse_key: "New Connections", content_available: true,  priority: "high"}
                gcm.send(registration_ids, options)
                {success: true}.to_json
            rescue => e
                {success: false, error: e.to_s}
            end
        end
    end
end

这里也是我的procfile: web: bundle exec thin start -p $PORT worker: bundle exec sidekiq -c 5 -v -r ./app/sidekiq.rb

以下是错误消息:

Failed uninitialized constant Socio::ConfirmNotificationWorker::User

我尝试了不同的require和include命令,但无法使其工作。

0 个答案:

没有答案