sidekiq相同的作业被执行了多次

问题描述 投票:0回答:1

红宝石2.4.4p296(2018-03-28修订版63013)[x86_64-darwin18]

Sidekiq v5.2.7

macOS Catalina 10.15.1

我正在尝试使用sidekiq运行一个简单的rails项目,当我单击链接时,该项目会在终端中显示“ hello”。这必须打印一次“ hello”,但是同一作业执行了20次。

我已经重新安装了Redis,重新启动了我的笔记本电脑,尝试将Sidekiq与另一个新的滑轨一起使用,但是没有任何解决方案能够解决我的问题。

这是我的代码:

# app/workers/kakao_worker.rb
class KakaoWorker
  include Sidekiq::Worker

  def perform
    pp "hello"
  end
end
# app/controllers/home_controller.rb
class HomeController < ApplicationController
  def index
  end

  def kakao
    KakaoWorker.perform_async
    redirect_to root_path
  end
end
# app/views/home/index.html.erb
<%= link_to 'sidekiq example', kakao_path %>
# config/routes.rb
Rails.application.routes.draw do
  root 'home#index'
  get '/kakao' => 'home#kakao'

  # sidekiq
  require 'sidekiq/web'
  mount Sidekiq::Web => '/sidekiq'
end

结果:

~/Desktop/rails_workspace/sidekiq-test master* 10s
❯ bundle exec sidekiq


         m,
         `$b
    .ss,  $$:         .,d$
    `$$P,d$P'    .,md$P"'
     ,$$$$$bmmd$$$P^'
   .d$$$$$$$$$$P'
   $$^' `"^$$$'       ____  _     _      _    _
   $:     ,$$:       / ___|(_) __| | ___| | _(_) __ _
   `b     :$$        \___ \| |/ _` |/ _ \ |/ / |/ _` |
          $$:         ___) | | (_| |  __/   <| | (_| |
          $$         |____/|_|\__,_|\___|_|\_\_|\__, |
        .d$$                                       |_|

2020-01-10T12:11:08.349Z 22393 TID-owqttmdqh INFO: Running in ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-darwin18]
2020-01-10T12:11:08.350Z 22393 TID-owqttmdqh INFO: See LICENSE and the LGPL-3.0 for licensing details.
2020-01-10T12:11:08.350Z 22393 TID-owqttmdqh INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2020-01-10T12:11:08.350Z 22393 TID-owqttmdqh INFO: Booting Sidekiq 5.2.7 with redis options {:id=>"Sidekiq-server-PID-22393", :url=>nil}
2020-01-10T12:11:08.366Z 22393 TID-owqttmdqh INFO: Starting processing, hit Ctrl-C to stop
2020-01-10T12:11:08.367Z 22393 TID-owqu4ec0p KakaoWorker JID-6bf94ecf1317a4457c3dea44 INFO: start
"hello"
2020-01-10T12:11:08.426Z 22393 TID-owqu4ec0p KakaoWorker JID-6bf94ecf1317a4457c3dea44 INFO: done: 0.059 sec
2020-01-10T12:11:08.426Z 22393 TID-owqu4ec0p KakaoWorker JID-c99c10bef2ee95aab26b3720 INFO: start
"hello"
2020-01-10T12:11:08.427Z 22393 TID-owqu4ec0p KakaoWorker JID-c99c10bef2ee95aab26b3720 INFO: done: 0.0 sec
2020-01-10T12:11:08.427Z 22393 TID-owqu4ec0p KakaoWorker JID-c8aa3efe5fd7ad3c19389e5a INFO: start
"hello"
2020-01-10T12:11:08.427Z 22393 TID-owqu4ec0p KakaoWorker JID-c8aa3efe5fd7ad3c19389e5a INFO: done: 0.0 sec
2020-01-10T12:11:08.427Z 22393 TID-owqu4ec0p KakaoWorker JID-bb559a18ba413d6649ed118e INFO: start
"hello"
2020-01-10T12:11:08.428Z 22393 TID-owqu4ec0p KakaoWorker JID-bb559a18ba413d6649ed118e INFO: done: 0.0 sec
2020-01-10T12:11:08.428Z 22393 TID-owqu4ec0p KakaoWorker JID-17f08cba621ea70a80634ae3 INFO: start
"hello"
2020-01-10T12:11:08.428Z 22393 TID-owqu4ec0p KakaoWorker JID-17f08cba621ea70a80634ae3 INFO: done: 0.0 sec
2020-01-10T12:11:08.428Z 22393 TID-owqu4ec0p KakaoWorker JID-bdc1f3fc52f691010436d4b6 INFO: start
"hello"
2020-01-10T12:11:08.429Z 22393 TID-owqu4ec0p KakaoWorker JID-bdc1f3fc52f691010436d4b6 INFO: done: 0.0 sec
2020-01-10T12:11:08.429Z 22393 TID-owqu4ec0p KakaoWorker JID-73cd00eaabe5ef1998ae5d81 INFO: start
"hello"
2020-01-10T12:11:08.429Z 22393 TID-owqu4ec0p KakaoWorker JID-73cd00eaabe5ef1998ae5d81 INFO: done: 0.0 sec
2020-01-10T12:11:08.429Z 22393 TID-owqu4ec0p KakaoWorker JID-4afc35e4a47374919b84e8b7 INFO: start
"hello"
2020-01-10T12:11:08.430Z 22393 TID-owqu4ec0p KakaoWorker JID-4afc35e4a47374919b84e8b7 INFO: done: 0.0 sec
2020-01-10T12:11:08.430Z 22393 TID-owqu4ec0p KakaoWorker JID-677989b8589ae674b505dffa INFO: start
"hello"
2020-01-10T12:11:08.430Z 22393 TID-owqu4ec0p KakaoWorker JID-677989b8589ae674b505dffa INFO: done: 0.0 sec
2020-01-10T12:11:08.430Z 22393 TID-owqu4ec0p KakaoWorker JID-505f2e333c1cf88173545ffc INFO: start
"hello"
2020-01-10T12:11:08.431Z 22393 TID-owqu4ec0p KakaoWorker JID-505f2e333c1cf88173545ffc INFO: done: 0.0 sec
2020-01-10T12:11:08.431Z 22393 TID-owqu4ec0p KakaoWorker JID-eb8f47de2286c3c250d3d90a INFO: start
"hello"
2020-01-10T12:11:08.431Z 22393 TID-owqu4ec0p KakaoWorker JID-eb8f47de2286c3c250d3d90a INFO: done: 0.0 sec
2020-01-10T12:11:08.432Z 22393 TID-owqu4ec0p KakaoWorker JID-19d998b6159ba42131d99b83 INFO: start
"hello"
2020-01-10T12:11:08.432Z 22393 TID-owqu4ec0p KakaoWorker JID-19d998b6159ba42131d99b83 INFO: done: 0.0 sec
2020-01-10T12:11:08.432Z 22393 TID-owqu4ec0p KakaoWorker JID-08faaaefb6eaa058c0fdda4f INFO: start
"hello"
2020-01-10T12:11:08.433Z 22393 TID-owqu4ec0p KakaoWorker JID-08faaaefb6eaa058c0fdda4f INFO: done: 0.0 sec
2020-01-10T12:11:08.433Z 22393 TID-owqu4ec0p KakaoWorker JID-553af6475c8495cfb66076d1 INFO: start
"hello"
2020-01-10T12:11:08.433Z 22393 TID-owqu4ec0p KakaoWorker JID-553af6475c8495cfb66076d1 INFO: done: 0.0 sec
2020-01-10T12:11:08.434Z 22393 TID-owqu4ec0p KakaoWorker JID-01375d9cced621abdde31215 INFO: start
"hello"
2020-01-10T12:11:08.434Z 22393 TID-owqu4ec0p KakaoWorker JID-01375d9cced621abdde31215 INFO: done: 0.0 sec
2020-01-10T12:11:08.434Z 22393 TID-owqu4ec0p KakaoWorker JID-a9c118f8795beae0904f0195 INFO: start
"hello"
2020-01-10T12:11:08.435Z 22393 TID-owqu4ec0p KakaoWorker JID-a9c118f8795beae0904f0195 INFO: done: 0.0 sec
2020-01-10T12:11:08.435Z 22393 TID-owqu4ec0p KakaoWorker JID-0fc0c04eb576e716d4bba9d3 INFO: start
"hello"
2020-01-10T12:11:08.435Z 22393 TID-owqu4ec0p KakaoWorker JID-0fc0c04eb576e716d4bba9d3 INFO: done: 0.0 sec
2020-01-10T12:11:08.435Z 22393 TID-owqu4ec0p KakaoWorker JID-674ddf2034eaa60fa3c84f0e INFO: start
"hello"
2020-01-10T12:11:08.436Z 22393 TID-owqu4ec0p KakaoWorker JID-674ddf2034eaa60fa3c84f0e INFO: done: 0.001 sec
2020-01-10T12:11:08.436Z 22393 TID-owqu4ec0p KakaoWorker JID-436a06f105fbc3361ac5e968 INFO: start
"hello"
2020-01-10T12:11:08.437Z 22393 TID-owqu4ec0p KakaoWorker JID-436a06f105fbc3361ac5e968 INFO: done: 0.001 sec
2020-01-10T12:11:08.437Z 22393 TID-owqu4ec0p KakaoWorker JID-b6b4ccb4e3a71db55df60194 INFO: start
"hello"
2020-01-10T12:11:08.437Z 22393 TID-owqu4ec0p KakaoWorker JID-b6b4ccb4e3a71db55df60194 INFO: done: 0.0 sec

尝试使用另一台笔记本电脑效果很好,所以我认为这是我的笔记本电脑问题。有人可以帮我解决这个问题吗?还添加了config.active_job.queue_adapter = :sidekiq中的config/application.rbSidekiq::Extensions.enable_delay!文件中的config/sidekiq.rb

ruby-on-rails ruby sidekiq
1个回答
0
投票
您可以通过其nice admin UI监视sidekiq。

您还可以打开

redis-cli,使用

MONITOR可以实时查看正在发生的事情。

© www.soinside.com 2019 - 2024. All rights reserved.