diff --git a/Envfile b/Envfile index 1a812559d..1adf35299 100644 --- a/Envfile +++ b/Envfile @@ -40,6 +40,9 @@ variable :REDIS_SESSIONS_URL, :String, default: "redis://localhost:6379" variable :SESSION_KEY, :String, default: "_Dev_Community_Session" variable :SESSION_EXPIRY_SECONDS, :Integer, default: 1209600 # two weeks in seconds +# Redis Sidekiq storage +variable :REDIS_SIDEKIQ_URL, :String, default: "redis://localhost:6379" + ################################################ ############## 3rd Party Services ############## ################################################ diff --git a/Gemfile b/Gemfile index 8c2d6dd18..25fd32647 100644 --- a/Gemfile +++ b/Gemfile @@ -82,6 +82,7 @@ gem "rouge", "~> 3.14" # A pure-ruby code highlighter gem "rubyzip", "~> 2.0" # Rubyzip is a ruby library for reading and writing zip files gem "s3_direct_upload", "~> 0.1" # Direct Upload to Amazon S3 gem "sass-rails", "~> 6.0" # Sass adapter for the Rails asset pipeline +gem "sidekiq", "~> 6.0.4" # Sidekiq is used to process background jobs with the help of Redis gem "sitemap_generator", "~> 6.0" # SitemapGenerator is a framework-agnostic XML Sitemap generator gem "skylight", "~> 4.2" # Skylight is a smart profiler for Rails, Sinatra, and other Ruby apps gem "slack-notifier", "~> 2.3" # A slim ruby wrapper for posting to slack webhooks diff --git a/Gemfile.lock b/Gemfile.lock index 70d27059c..9403b2c88 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -723,6 +723,11 @@ GEM shellany (0.0.1) shoulda-matchers (4.1.2) activesupport (>= 4.2.0) + sidekiq (6.0.4) + connection_pool (>= 2.2.2) + rack (>= 2.0.0) + rack-protection (>= 2.0.0) + redis (>= 4.1.0) signet (0.12.0) addressable (~> 2.3) faraday (~> 0.9) @@ -966,6 +971,7 @@ DEPENDENCIES sass-rails (~> 6.0) sdoc (~> 1.0) shoulda-matchers (= 4.1.2) + sidekiq (~> 6.0.4) simplecov (~> 0.17) sitemap_generator (~> 6.0) skylight (~> 4.2) diff --git a/Procfile b/Procfile index 2fd56bb5f..67c796ecb 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,4 @@ release: STATEMENT_TIMEOUT=180000 bundle exec rails db:migrate web: bin/start-pgbouncer bundle exec puma -C config/puma.rb worker: bundle exec rails jobs:work +sidekiq_worker: bundle exec sidekiq -t 25 diff --git a/Procfile.dev b/Procfile.dev index f60935238..3e104f1a1 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,4 @@ web: bin/rails s -p 3000 webpacker: ./bin/webpack-dev-server job: bin/rake jobs:work +sidekiq: bundle exec sidekiq diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 000000000..baa6e56d2 --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,4 @@ +Sidekiq.configure_server do |config| + sidekiq_url = ApplicationConfig["REDIS_SIDEKIQ_URL"] || ApplicationConfig["REDIS_URL"] + config.redis = { url: sidekiq_url } +end diff --git a/config/routes.rb b/config/routes.rb index e32421603..793d390a2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,8 +10,10 @@ Rails.application.routes.draw do registrations: "registrations" } + require "sidekiq/web" authenticated :user, ->(user) { user.tech_admin? } do mount DelayedJobWeb, at: "/delayed_job" + mount Sidekiq::Web => "/sidekiq" end devise_scope :user do diff --git a/docs/technical-overview/stack.md b/docs/technical-overview/stack.md index 3806be0f6..3869002e6 100644 --- a/docs/technical-overview/stack.md +++ b/docs/technical-overview/stack.md @@ -15,8 +15,9 @@ For the Dev.to tech stack we use: - [_Honeybadger_](https://www.honeybadger.io/) for error monitoring - [_Timber_](https://timber.io/) for logging - [_Delayed Job_](https://github.com/collectiveidea/delayed_job) and - [_Active Job_](https://guides.rubyonrails.org/active_job_basics.html) for - background workers +- [_Sidekiq_](https://github.com/mperham/sidekiq) (will be replacing delayed + job) and [_Active Job_](https://guides.rubyonrails.org/active_job_basics.html) + for background workers - [_Algolia_](https://www.algolia.com/) for search - [_Redcarpet_](https://github.com/vmg/redcarpet) and [_Rouge_](https://github.com/jneen/rouge) to parse Markdown diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 54d828d81..f1f046be6 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -14,6 +14,7 @@ require "webmock/rspec" require "test_prof/recipes/rspec/before_all" require "test_prof/recipes/rspec/let_it_be" require "test_prof/recipes/rspec/sample" +require "sidekiq/testing" # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are