繁体   English   中英

Sidekiq滑轨无法执行工作

[英]Sidekiq rails not performing job

家庭控制器:

class HomeController < ApplicationController


    def index
        if request.post?
          @value = (params[:value] || 10).to_i 
          # Perform the calculation of the fibonnaci in background
          puts('starting job...')
          TestJob.perform_async("Luis",@value)
        end

        # Retrieve from Redis the last 10 calculations
        @bottom = redis.lrange("calcs",-10,-1).reverse
    end

    private
     def redis
    @redis ||= Redis.new
  end
end

HTML erb文件(查看)

Fibonnaci calculator (try a few between 30 and 40)
<%= form_tag(home_index_path) do %>
  <%= text_field_tag(:value,@value) %>
  <%= submit_tag(:calculate) %>
<% end %>

Past completed calculations
<ul>
  <% @bottom.each do |value| %>
    <li><%= value %></li>
  <% end %>
</ul>

TestJob类

class TestJob
  include Sidekiq::Worker

  # Calculate the nth fibonnaci sequence number
  def fib(x)
    return 0 if x < 1
    x < 3 ? 1 : fib(x-1) + fib(x-2)
  end

  # Sidekiq has the same interface as resque, so we can call this method asynchronously by using SlowJob.perform_async
  # When #perform_async is called the arguments are serialized to a Redis queue and later our background job processor
  # will dequeue them and call the #perform method below with them
  def perform(name, number)
    time = Time.now
    # Recursive Fibonnaci of larger than 30 numbers can take a while
    result = fib(number)
    duration = Time.now - time

    text =  "Dear #{name} the Fibonacci value of #{number} is #{result} (#{"%.2f" % duration }) #{time.strftime("%F %T")}"

    # Put the results in a redis list so we can see them on the web interface at each new request
    redis.rpush "calcs", text
  end

  # Create a redis client
  def redis
    @redis ||= Redis.new
  end
end

因此,当我以HTML提交表单时,例如,我在表单中放入5,然后成功发送了发布请求,并且我绝对看不到错误。

我在控制台中看到以下输出:

Started POST "/home/index" for 127.0.0.1 at 2015-10-05 17:23:35 +0530
Processing by HomeController#index as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"cgQMV3sCP91zaeiPfYVC5mxfBZpDmgKgRZ7qe5PWCdqGUX59v8I4BZoKXbdYlqfsLyp6/cz8XY/3cEXe/mKh4A==", "value"=>"5", "commit"=>"calculate"}
starting job...
  Rendered home/index.html.erb within layouts/application (0.8ms)
Completed 200 OK in 81ms (Views: 76.1ms | ActiveRecord: 0.0ms)

而且我在HTML文件中看不到任何内容。 作业未执行。

您开始了sidekiq工作者吗?

bundle exec sidekiq

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM