From 799612170343a84228d384190b93c550886730ea Mon Sep 17 00:00:00 2001 From: graph1589 Date: Sat, 22 Jan 2022 10:23:12 +0300 Subject: [PATCH 1/6] configured sidekiq --- Gemfile | 1 + Gemfile.lock | 7 +++++++ config/initializers/sidekiq.rb | 7 +++++++ config/sidekiq.yml | 4 ++++ docker-compose.yml | 12 ++++++++++++ test/test_helper.rb | 1 + 6 files changed, 32 insertions(+) create mode 100644 config/initializers/sidekiq.rb create mode 100644 config/sidekiq.yml diff --git a/Gemfile b/Gemfile index 7f8aa8b..c2195e7 100644 --- a/Gemfile +++ b/Gemfile @@ -73,3 +73,4 @@ gem 'webpacker-react', '~> 0.3.2' gem 'js-routes' gem 'rollbar' gem 'newrelic_rpm' +gem 'sidekiq' diff --git a/Gemfile.lock b/Gemfile.lock index 161fda5..2c86d47 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,6 +99,7 @@ GEM activesupport childprocess (4.1.0) concurrent-ruby (1.1.9) + connection_pool (2.2.5) coveralls (0.7.1) multi_json (~> 1.3) rest-client @@ -220,6 +221,7 @@ GEM rb-fsevent (0.11.0) rb-inotify (0.10.1) ffi (~> 1.0) + redis (4.5.1) regexp_parser (2.1.1) responders (3.0.1) actionpack (>= 5.0) @@ -259,6 +261,10 @@ GEM rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2) semantic_range (3.0.0) + sidekiq (6.4.0) + connection_pool (>= 2.2.2) + rack (~> 2.0) + redis (>= 4.2.0) simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) @@ -357,6 +363,7 @@ DEPENDENCIES rubocop sass-rails (>= 6) selenium-webdriver + sidekiq simple_form simplecov simplecov-lcov diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb new file mode 100644 index 0000000..46dfd78 --- /dev/null +++ b/config/initializers/sidekiq.rb @@ -0,0 +1,7 @@ +Sidekiq.configure_server do |config| + config.redis = { url: ENV['REDIS_URL'] } +end + +Sidekiq.configure_client do |config| + config.redis = { url: ENV['REDIS_URL'] } +end \ No newline at end of file diff --git a/config/sidekiq.yml b/config/sidekiq.yml new file mode 100644 index 0000000..287bc9c --- /dev/null +++ b/config/sidekiq.yml @@ -0,0 +1,4 @@ +:concurrency: 5 +:verbose: true +:queues: + - default \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2dd329a..9ca50e6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,15 @@ version: '3.7' services: + sidekiq: + build: . + command: bundle exec sidekiq -C /task_manager/config/sidekiq.yml + environment: *web-environment + volumes: *web-volumes + depends_on: + - redis + redis: + image: redis:5.0.9-alpine web: build: . volumes: &web-volumes @@ -14,7 +23,10 @@ services: - 3002:3002 depends_on: - db + - redis + - sidekiq environment: &web-environment + REDIS_URL: redis://redis BUNDLE_PATH: /bundle_cache GEM_HOME: /bundle_cache GEM_PATH: /bundle_cache diff --git a/test/test_helper.rb b/test/test_helper.rb index 9962dfc..0d9e4dd 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,6 +21,7 @@ ENV['RAILS_ENV'] ||= 'test' require_relative '../config/environment' require 'rails/test_help' +require 'sidekiq/testing' class ActiveSupport::TestCase include ActionMailer::TestHelper From 4f080a659d1c02e35857670fa0c2ae5745696746 Mon Sep 17 00:00:00 2001 From: graph1589 Date: Sat, 22 Jan 2022 10:28:37 +0300 Subject: [PATCH 2/6] configured mails by sidekiq --- config/application.rb | 2 ++ config/sidekiq.yml | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index f50bc78..95a1b7a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -12,6 +12,8 @@ class Application < Rails::Application config.load_defaults 6.1 config.assets.paths << Rails.root.join('node_modules') + config.active_job.queue_adapter = :sidekiq + # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 287bc9c..f4b932e 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -1,4 +1,6 @@ +--- :concurrency: 5 :verbose: true :queues: - - default \ No newline at end of file + - default + - mailers \ No newline at end of file From 64c36e0285ab5941054d156f3a35acfdda022845 Mon Sep 17 00:00:00 2001 From: graph1589 Date: Sat, 22 Jan 2022 10:58:33 +0300 Subject: [PATCH 3/6] mounted sidekiq control panel --- Gemfile | 1 + Gemfile.lock | 3 +++ app/controllers/api/v1/tasks_controller.rb | 6 +++--- config/initializers/sidekiq.rb | 2 ++ config/routes.rb | 1 + docker-compose.yml | 19 +++++++++---------- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index c2195e7..b4d8fd3 100644 --- a/Gemfile +++ b/Gemfile @@ -74,3 +74,4 @@ gem 'js-routes' gem 'rollbar' gem 'newrelic_rpm' gem 'sidekiq' +gem 'sidekiq-failures' diff --git a/Gemfile.lock b/Gemfile.lock index 2c86d47..30f592f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -265,6 +265,8 @@ GEM connection_pool (>= 2.2.2) rack (~> 2.0) redis (>= 4.2.0) + sidekiq-failures (1.0.1) + sidekiq (>= 4.0.0) simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) @@ -364,6 +366,7 @@ DEPENDENCIES sass-rails (>= 6) selenium-webdriver sidekiq + sidekiq-failures simple_form simplecov simplecov-lcov diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 08c85f8..7844fd8 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -19,7 +19,7 @@ def create task = current_user.my_tasks.new(task_params) if task.save - UserMailer.with({ user: current_user, task: task }).task_created.deliver_now + UserMailer.with({ user: current_user, task: task }).task_created.deliver_later end respond_with(task, serializer: TaskSerializer, location: nil) @@ -29,7 +29,7 @@ def update task = Task.find(params[:id]) if task.update(task_params) - UserMailer.with({ task: task }).task_updated.deliver_now + UserMailer.with({ task: task }).task_updated.deliver_later end respond_with(task, serializer: TaskSerializer) @@ -39,7 +39,7 @@ def destroy task = Task.find(params[:id]) if task.destroy - UserMailer.with({ task: task }).task_destroyed.deliver_now + UserMailer.with({ task: task }).task_destroyed.deliver_later end respond_with(task) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 46dfd78..0a0a39b 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,3 +1,5 @@ +require 'sidekiq/web' + Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } end diff --git a/config/routes.rb b/config/routes.rb index 346b34a..299849a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + mount Sidekiq::Web => '/admin/sidekiq' mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? root :to => "web/boards#show" diff --git a/docker-compose.yml b/docker-compose.yml index 9ca50e6..9ea9fb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,6 @@ version: '3.7' services: - sidekiq: - build: . - command: bundle exec sidekiq -C /task_manager/config/sidekiq.yml - environment: *web-environment - volumes: *web-volumes - depends_on: - - redis - redis: - image: redis:5.0.9-alpine web: build: . volumes: &web-volumes @@ -36,7 +27,6 @@ services: DATABASE_USERNAME: postgres DATABASE_PASSWORD: postgres command: bundle exec rails s -b '0.0.0.0' -p 3000 - db: image: postgres:11.4 ports: @@ -44,6 +34,15 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + sidekiq: + build: . + command: bundle exec sidekiq -C /task_manager/config/sidekiq.yml + environment: *web-environment + volumes: *web-volumes + depends_on: + - redis + redis: + image: redis:5.0.9-alpine volumes: bundle_cache: \ No newline at end of file From 5a6227d146f275a194c20e1340025b0af2b5c77e Mon Sep 17 00:00:00 2001 From: graph1589 Date: Sun, 23 Jan 2022 17:25:37 +0300 Subject: [PATCH 4/6] added mails send limit --- Gemfile | 1 + Gemfile.lock | 6 ++++++ app/controllers/api/v1/tasks_controller.rb | 8 +++++--- app/jobs/application_job.rb | 9 +++------ app/jobs/send_password_reset_notification_job.rb | 11 +++++++++++ app/jobs/send_task_create_notification_job.rb | 11 +++++++++++ app/jobs/send_task_destroy_notification_job.rb | 11 +++++++++++ app/jobs/send_task_update_notification_job.rb | 11 +++++++++++ app/services/user_service.rb | 4 +++- config/initializers/sidekiq.rb | 8 +++++++- test/mailers/user_mailer_test.rb | 4 ++-- test/test_helper.rb | 2 ++ 12 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 app/jobs/send_password_reset_notification_job.rb create mode 100644 app/jobs/send_task_create_notification_job.rb create mode 100644 app/jobs/send_task_destroy_notification_job.rb create mode 100644 app/jobs/send_task_update_notification_job.rb diff --git a/Gemfile b/Gemfile index b4d8fd3..1a26f1d 100644 --- a/Gemfile +++ b/Gemfile @@ -75,3 +75,4 @@ gem 'rollbar' gem 'newrelic_rpm' gem 'sidekiq' gem 'sidekiq-failures' +gem 'sidekiq-throttled' diff --git a/Gemfile.lock b/Gemfile.lock index 30f592f..8d04ff0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -222,6 +222,7 @@ GEM rb-inotify (0.10.1) ffi (~> 1.0) redis (4.5.1) + redis-prescription (1.0.0) regexp_parser (2.1.1) responders (3.0.1) actionpack (>= 5.0) @@ -267,6 +268,10 @@ GEM redis (>= 4.2.0) sidekiq-failures (1.0.1) sidekiq (>= 4.0.0) + sidekiq-throttled (0.15.0) + concurrent-ruby + redis-prescription + sidekiq simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) @@ -367,6 +372,7 @@ DEPENDENCIES selenium-webdriver sidekiq sidekiq-failures + sidekiq-throttled simple_form simplecov simplecov-lcov diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 7844fd8..2e93e90 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -19,7 +19,7 @@ def create task = current_user.my_tasks.new(task_params) if task.save - UserMailer.with({ user: current_user, task: task }).task_created.deliver_later + SendTaskCreateNotificationJob.perform_async(task.id) end respond_with(task, serializer: TaskSerializer, location: nil) @@ -29,7 +29,8 @@ def update task = Task.find(params[:id]) if task.update(task_params) - UserMailer.with({ task: task }).task_updated.deliver_later + SendTaskUpdateNotificationJob.perform_async(task.id) + # UserMailer.with({ task: task }).task_updated.deliver_later end respond_with(task, serializer: TaskSerializer) @@ -39,7 +40,8 @@ def destroy task = Task.find(params[:id]) if task.destroy - UserMailer.with({ task: task }).task_destroyed.deliver_later + SendTaskDestroyNotificationJob.perform_async(task.id) + # UserMailer.with({ task: task }).task_destroyed.deliver_later end respond_with(task) diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index d394c3d..2641584 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,7 +1,4 @@ -class ApplicationJob < ActiveJob::Base - # Automatically retry jobs that encountered a deadlock - # retry_on ActiveRecord::Deadlocked - - # Most jobs are safe to ignore if the underlying records are no longer available - # discard_on ActiveJob::DeserializationError +class ApplicationJob + include Sidekiq::Worker + include Sidekiq::Throttled::Worker end diff --git a/app/jobs/send_password_reset_notification_job.rb b/app/jobs/send_password_reset_notification_job.rb new file mode 100644 index 0000000..54692dd --- /dev/null +++ b/app/jobs/send_password_reset_notification_job.rb @@ -0,0 +1,11 @@ +class SendPasswordResetNotificationJob < ApplicationJob + sidekiq_options queue: :mailers + sidekiq_throttle_as :mailer + + def perform(user_id) + user = User.find_by(id: user_id) + return if user.blank? + + UserMailer.with({ user: user }).reset_password.deliver_now + end +end \ No newline at end of file diff --git a/app/jobs/send_task_create_notification_job.rb b/app/jobs/send_task_create_notification_job.rb new file mode 100644 index 0000000..ef4bbf5 --- /dev/null +++ b/app/jobs/send_task_create_notification_job.rb @@ -0,0 +1,11 @@ +class SendTaskCreateNotificationJob < ApplicationJob + sidekiq_options queue: :mailers + sidekiq_throttle_as :mailer + + def perform(task_id) + task = Task.find_by(id: task_id) + return if task.blank? + + UserMailer.with(user: task.author, task: task).task_created.deliver_now + end +end \ No newline at end of file diff --git a/app/jobs/send_task_destroy_notification_job.rb b/app/jobs/send_task_destroy_notification_job.rb new file mode 100644 index 0000000..1f24231 --- /dev/null +++ b/app/jobs/send_task_destroy_notification_job.rb @@ -0,0 +1,11 @@ +class SendTaskDestroyNotificationJob < ApplicationJob + sidekiq_options queue: :mailers + sidekiq_throttle_as :mailer + + def perform(task_id) + task = Task.find_by(id: task_id) + return if task.blank? + + UserMailer.with(user: task.author, task: task).task_destroyed.deliver_now + end +end \ No newline at end of file diff --git a/app/jobs/send_task_update_notification_job.rb b/app/jobs/send_task_update_notification_job.rb new file mode 100644 index 0000000..f75f7fe --- /dev/null +++ b/app/jobs/send_task_update_notification_job.rb @@ -0,0 +1,11 @@ +class SendTaskUpdateNotificationJob < ApplicationJob + sidekiq_options queue: :mailers + sidekiq_throttle_as :mailer + + def perform(task_id) + task = Task.find_by(id: task_id) + return if task.blank? + + UserMailer.with(user: task.author, task: task).task_updated.deliver_now + end +end \ No newline at end of file diff --git a/app/services/user_service.rb b/app/services/user_service.rb index 4c2798f..c96c209 100644 --- a/app/services/user_service.rb +++ b/app/services/user_service.rb @@ -3,7 +3,9 @@ def self.reset_password!(user) token = SecureRandom.hex(10) user.update!(reset_digest: token, reset_sent_at: Time.current) - UserMailer.with({ user: user }).reset_password.deliver_now + SendPasswordResetNotificationJob.perform_async(user.id) + + #UserMailer.with({ user: user }).reset_password.deliver_later end def self.password_reset_period_valid?(user) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 0a0a39b..5d39cef 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,4 +1,6 @@ require 'sidekiq/web' +require "sidekiq/throttled" +require "sidekiq/throttled/web" Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } @@ -6,4 +8,8 @@ Sidekiq.configure_client do |config| config.redis = { url: ENV['REDIS_URL'] } -end \ No newline at end of file +end + +Sidekiq::Throttled.setup! + +Sidekiq::Throttled::Registry.add(:mailer, { threshold: { limit: 1, period: 5.seconds } }) diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb index 63f7c3b..8e4ab0a 100644 --- a/test/mailers/user_mailer_test.rb +++ b/test/mailers/user_mailer_test.rb @@ -8,7 +8,7 @@ class UserMailerTest < ActionMailer::TestCase email = UserMailer.with(params).task_created assert_emails 1 do - email.deliver_now + email.deliver_later end assert_equal ['noreply@taskmanager.com'], email.from @@ -25,7 +25,7 @@ class UserMailerTest < ActionMailer::TestCase email = UserMailer.with({ user: user }).reset_password assert_emails 1 do - email.deliver_now + email.deliver_later end assert_equal ['noreply@taskmanager.com'], email.from diff --git a/test/test_helper.rb b/test/test_helper.rb index 0d9e4dd..80e4a93 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -28,3 +28,5 @@ class ActiveSupport::TestCase include AuthHelper include FactoryBot::Syntax::Methods end + +Sidekiq::Testing.inline! From 07be06e992fc4cb63fe78a80f743e9afbd5d7c4a Mon Sep 17 00:00:00 2001 From: graph1589 Date: Sun, 23 Jan 2022 17:33:31 +0300 Subject: [PATCH 5/6] setting uniqueness --- Gemfile | 1 + Gemfile.lock | 5 +++++ app/jobs/send_task_update_notification_job.rb | 1 + config/initializers/sidekiq.rb | 1 + test/test_helper.rb | 4 ++-- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 1a26f1d..cc4df53 100644 --- a/Gemfile +++ b/Gemfile @@ -76,3 +76,4 @@ gem 'newrelic_rpm' gem 'sidekiq' gem 'sidekiq-failures' gem 'sidekiq-throttled' +gem 'sidekiq-unique-jobs', '~> 6.0.13' diff --git a/Gemfile.lock b/Gemfile.lock index 8d04ff0..d4a2f99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -272,6 +272,10 @@ GEM concurrent-ruby redis-prescription sidekiq + sidekiq-unique-jobs (6.0.25) + concurrent-ruby (~> 1.0, >= 1.0.5) + sidekiq (>= 4.0, < 7.0) + thor (>= 0.20, < 2.0) simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) @@ -373,6 +377,7 @@ DEPENDENCIES sidekiq sidekiq-failures sidekiq-throttled + sidekiq-unique-jobs (~> 6.0.13) simple_form simplecov simplecov-lcov diff --git a/app/jobs/send_task_update_notification_job.rb b/app/jobs/send_task_update_notification_job.rb index f75f7fe..a6dd0a5 100644 --- a/app/jobs/send_task_update_notification_job.rb +++ b/app/jobs/send_task_update_notification_job.rb @@ -1,6 +1,7 @@ class SendTaskUpdateNotificationJob < ApplicationJob sidekiq_options queue: :mailers sidekiq_throttle_as :mailer + sidekiq_options lock: :until_and_while_executing, on_conflict: { client: :log, server: :reject } def perform(task_id) task = Task.find_by(id: task_id) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index 5d39cef..a54c4b6 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -1,6 +1,7 @@ require 'sidekiq/web' require "sidekiq/throttled" require "sidekiq/throttled/web" +require 'sidekiq_unique_jobs/web' Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } diff --git a/test/test_helper.rb b/test/test_helper.rb index 80e4a93..94a3ff7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,10 +23,10 @@ require 'rails/test_help' require 'sidekiq/testing' +Sidekiq::Testing.inline! + class ActiveSupport::TestCase include ActionMailer::TestHelper include AuthHelper include FactoryBot::Syntax::Methods end - -Sidekiq::Testing.inline! From a85448e11893eb51d6d06f7c264fa710bdaabdbf Mon Sep 17 00:00:00 2001 From: graph1589 Date: Wed, 26 Jan 2022 17:57:55 +0300 Subject: [PATCH 6/6] fixed problems --- Gemfile | 2 +- Gemfile.lock | 12 ++++++++---- app/controllers/api/v1/tasks_controller.rb | 2 -- app/jobs/send_password_reset_notification_job.rb | 2 +- app/jobs/send_task_create_notification_job.rb | 2 +- app/jobs/send_task_destroy_notification_job.rb | 2 +- app/jobs/send_task_update_notification_job.rb | 4 ++-- app/services/user_service.rb | 2 -- config/initializers/sidekiq.rb | 8 ++++---- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index cc4df53..3b9bf4d 100644 --- a/Gemfile +++ b/Gemfile @@ -76,4 +76,4 @@ gem 'newrelic_rpm' gem 'sidekiq' gem 'sidekiq-failures' gem 'sidekiq-throttled' -gem 'sidekiq-unique-jobs', '~> 6.0.13' +gem 'sidekiq-unique-jobs' diff --git a/Gemfile.lock b/Gemfile.lock index d4a2f99..f35b45e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -81,6 +81,9 @@ GEM bindex (0.8.1) bootsnap (1.9.1) msgpack (~> 1.0) + brpoplpush-redis_script (0.1.2) + concurrent-ruby (~> 1.0, >= 1.0.5) + redis (>= 1.0, <= 5.0) builder (3.2.4) bullet (7.0.0) activesupport (>= 3.0.0) @@ -272,10 +275,11 @@ GEM concurrent-ruby redis-prescription sidekiq - sidekiq-unique-jobs (6.0.25) + sidekiq-unique-jobs (7.1.12) + brpoplpush-redis_script (> 0.1.1, <= 2.0.0) concurrent-ruby (~> 1.0, >= 1.0.5) - sidekiq (>= 4.0, < 7.0) - thor (>= 0.20, < 2.0) + sidekiq (>= 5.0, < 8.0) + thor (>= 0.20, < 3.0) simple_form (5.1.0) actionpack (>= 5.2) activemodel (>= 5.2) @@ -377,7 +381,7 @@ DEPENDENCIES sidekiq sidekiq-failures sidekiq-throttled - sidekiq-unique-jobs (~> 6.0.13) + sidekiq-unique-jobs simple_form simplecov simplecov-lcov diff --git a/app/controllers/api/v1/tasks_controller.rb b/app/controllers/api/v1/tasks_controller.rb index 2e93e90..8d1048e 100644 --- a/app/controllers/api/v1/tasks_controller.rb +++ b/app/controllers/api/v1/tasks_controller.rb @@ -30,7 +30,6 @@ def update if task.update(task_params) SendTaskUpdateNotificationJob.perform_async(task.id) - # UserMailer.with({ task: task }).task_updated.deliver_later end respond_with(task, serializer: TaskSerializer) @@ -41,7 +40,6 @@ def destroy if task.destroy SendTaskDestroyNotificationJob.perform_async(task.id) - # UserMailer.with({ task: task }).task_destroyed.deliver_later end respond_with(task) diff --git a/app/jobs/send_password_reset_notification_job.rb b/app/jobs/send_password_reset_notification_job.rb index 54692dd..a2382a5 100644 --- a/app/jobs/send_password_reset_notification_job.rb +++ b/app/jobs/send_password_reset_notification_job.rb @@ -8,4 +8,4 @@ def perform(user_id) UserMailer.with({ user: user }).reset_password.deliver_now end -end \ No newline at end of file +end diff --git a/app/jobs/send_task_create_notification_job.rb b/app/jobs/send_task_create_notification_job.rb index ef4bbf5..b7105eb 100644 --- a/app/jobs/send_task_create_notification_job.rb +++ b/app/jobs/send_task_create_notification_job.rb @@ -8,4 +8,4 @@ def perform(task_id) UserMailer.with(user: task.author, task: task).task_created.deliver_now end -end \ No newline at end of file +end diff --git a/app/jobs/send_task_destroy_notification_job.rb b/app/jobs/send_task_destroy_notification_job.rb index 1f24231..83464aa 100644 --- a/app/jobs/send_task_destroy_notification_job.rb +++ b/app/jobs/send_task_destroy_notification_job.rb @@ -8,4 +8,4 @@ def perform(task_id) UserMailer.with(user: task.author, task: task).task_destroyed.deliver_now end -end \ No newline at end of file +end diff --git a/app/jobs/send_task_update_notification_job.rb b/app/jobs/send_task_update_notification_job.rb index a6dd0a5..78734cc 100644 --- a/app/jobs/send_task_update_notification_job.rb +++ b/app/jobs/send_task_update_notification_job.rb @@ -1,7 +1,7 @@ class SendTaskUpdateNotificationJob < ApplicationJob sidekiq_options queue: :mailers - sidekiq_throttle_as :mailer sidekiq_options lock: :until_and_while_executing, on_conflict: { client: :log, server: :reject } + sidekiq_throttle_as :mailer def perform(task_id) task = Task.find_by(id: task_id) @@ -9,4 +9,4 @@ def perform(task_id) UserMailer.with(user: task.author, task: task).task_updated.deliver_now end -end \ No newline at end of file +end diff --git a/app/services/user_service.rb b/app/services/user_service.rb index c96c209..492fa85 100644 --- a/app/services/user_service.rb +++ b/app/services/user_service.rb @@ -4,8 +4,6 @@ def self.reset_password!(user) user.update!(reset_digest: token, reset_sent_at: Time.current) SendPasswordResetNotificationJob.perform_async(user.id) - - #UserMailer.with({ user: user }).reset_password.deliver_later end def self.password_reset_period_valid?(user) diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb index a54c4b6..4263441 100644 --- a/config/initializers/sidekiq.rb +++ b/config/initializers/sidekiq.rb @@ -3,6 +3,10 @@ require "sidekiq/throttled/web" require 'sidekiq_unique_jobs/web' +Sidekiq::Throttled.setup! + +Sidekiq::Throttled::Registry.add(:mailer, { threshold: { limit: 1, period: 5.seconds } }) + Sidekiq.configure_server do |config| config.redis = { url: ENV['REDIS_URL'] } end @@ -10,7 +14,3 @@ Sidekiq.configure_client do |config| config.redis = { url: ENV['REDIS_URL'] } end - -Sidekiq::Throttled.setup! - -Sidekiq::Throttled::Registry.add(:mailer, { threshold: { limit: 1, period: 5.seconds } })