From 30789667d08d05bf010305c4ed1e1a2b5a0b3add Mon Sep 17 00:00:00 2001 From: Aaron Elkiss Date: Wed, 29 May 2024 10:57:45 -0400 Subject: [PATCH] Fix sidekiq web * add rack-session gem (needed by rack 3) * update standalone code from https://github.com/sidekiq/sidekiq/wiki/Monitoring#standalone * fix sidekiq_web service in docker-compose.yml --- Gemfile | 1 + Gemfile.lock | 3 +++ bin/sidekiq_web.ru | 26 +++++++++++--------------- docker-compose.yml | 2 ++ 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 5c522d18..e1f9f3ec 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem "sequel" gem "thor" gem "zinzout" gem "puma" +gem "rack-session" gem "sidekiq" gem "sidekiq-batch", git: "https://github.com/breamware/sidekiq-batch" diff --git a/Gemfile.lock b/Gemfile.lock index eb0825e7..34e9d826 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -101,6 +101,8 @@ GEM nio4r (~> 2.0) racc (1.8.0) rack (3.0.11) + rack-session (2.0.0) + rack (>= 3.0.0) rainbow (3.1.1) rdoc (6.6.3.1) psych (>= 4.0.0) @@ -212,6 +214,7 @@ DEPENDENCIES pry puma push_metrics! + rack-session rgl rspec rspec-sidekiq diff --git a/bin/sidekiq_web.ru b/bin/sidekiq_web.ru index 6d43d2f7..a69c4d34 100644 --- a/bin/sidekiq_web.ru +++ b/bin/sidekiq_web.ru @@ -1,18 +1,14 @@ -require "sidekiq" -require "sidekiq/web" -require_relative "../config/initializers/sidekiq" - -SESSION_KEY = ".session.key" - -if !File.exist?(SESSION_KEY) - require "securerandom" - File.open(SESSION_KEY, "w") do |f| - f.write(SecureRandom.hex(32)) - end -end +# This is sidekiq_web.ru +# Run with `bundle exec rackup sidekiq_web.ru` or similar. -Services.redis_config[:size] = 1 - -use Rack::Session::Cookie, secret: File.read(SESSION_KEY), same_site: true, max_age: 86400 +require "securerandom" +require "rack/session" +require "sidekiq/web" +# In a multi-process deployment, all Web UI instances should share +# this secret key so they can all decode the encrypted browser cookies +# and provide a working session. +# Rails does this in /config/initializers/secret_token.rb +secret_key = SecureRandom.hex(32) +use Rack::Session::Cookie, secret: secret_key, same_site: true, max_age: 86400 run Sidekiq::Web diff --git a/docker-compose.yml b/docker-compose.yml index 190d001d..655a288a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,6 +49,8 @@ services: <<: *holdings-container-defaults restart: always volumes: + - .:/usr/src/app + - gem_cache:/gems - ./example/datasets:/tmp/datasets command: bundle exec sidekiq -c 1 -r ./lib/sidekiq_jobs.rb