Sidekiq工人没有工作

时间:2015-10-31 09:56:29

标签: ruby-on-rails ruby-on-rails-4 notifications sidekiq

我尝试设置一个基本的通知工作程序来通知某个用户。 但在我的例子中,我的用户没有得到任何通知。

我的控制器操作,我试图执行我的工作人员:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.qn.sampleJboss</groupId>
    <artifactId>sample-boot-jboss</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.5.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <!-- <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin> </plugins> -->

        <plugins

            <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> 
                <configuration> <warName>sample-boot</warName> <outputDirectory>C:\jboss-eap-6.4\standalone\deployments</outputDirectory> 
                </configuration> </plugin>
        </plugins>

    </build>

</project>

我的notification_worker.rb

  def index
    NotificationWorker.delay().perform(current_user.id, 'error', 'refresh', 'test', 'asd')
    # ActionCable.server.broadcast "web_notifications_#{current_user.id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
  end

和我的通知模型:

class NotificationWorker
  include Sidekiq::Worker

  def perform(user_id, type, icon, title, body)
    Notification.create(user_id, type, icon, title, body)
  end
end

当我使用这个

class Notification < ActiveRecord::Base
  # belongs_to
  belongs_to :users

  def self.create(user_id, type, icon, title, body)
    ActionCable.server.broadcast "web_notifications_#{user_id}", { type: 'error', icon: 'refresh', title: 'title', body: 'body' }
  end
end

我的用户收到通知但我不想发送他们与sidekiq

1 个答案:

答案 0 :(得分:1)

根据我在评论中的假设 - 问题是你没有运行sidekiq。