Skip to content

Skip defering scheduled jobs in concurrency limit client middleware

Sylvester Chin requested to merge sc1-fix-climit-scheduled-jobs into master

What does this MR do and why?

Skip defering scheduled jobs in concurrency limit client middleware

This commit adds a check to omit Sidekiq scheduled jobs from the concurrency limit client middleware checks. These jobs can be checked and deferred when they are enqueued.

Fixes a functional bug where scheduled jobs are deferred and enqueued using .perform_async. This could result in the job being performed before its intended schedule.

Related to gitlab-com/gl-infra/scalability#3877

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Apply this diff
diff --git a/app/workers/chaos/sleep_worker.rb b/app/workers/chaos/sleep_worker.rb
index 149bab5d9d3c..1ad62b51e7ea 100644
--- a/app/workers/chaos/sleep_worker.rb
+++ b/app/workers/chaos/sleep_worker.rb
@@ -6,6 +6,8 @@ class SleepWorker # rubocop:disable Scalability/IdempotentWorker
 
     data_consistency :always
 
+    concurrency_limit -> { 1 }
+
     sidekiq_options retry: 3
     include ChaosQueue
  1. Restart gdk and open a console
➜  gitlab git:(sc1-fix-climit-scheduled-jobs) ✗ gdk restart rails
ok: down: /Users/sylvesterchin/work/gitlab-development-kit/services/rails-background-jobs: 1s
ok: down: /Users/sylvesterchin/work/gitlab-development-kit/services/rails-web: 0s
ok: run: /Users/sylvesterchin/work/gitlab-development-kit/services/rails-background-jobs: (pid 76221) 0s, normally down
ok: run: /Users/sylvesterchin/work/gitlab-development-kit/services/rails-web: (pid 76220) 0s, normally down
  1. Run (0..40).map { Chaos::SleepWorker.perform_async(2) } a bunch of times until you exceed the concurrency. You should see nil once that happens.
[6] pry(main)> x = (0..40).map { Chaos::SleepWorker.perform_async(2) }
=> ["e3df4dc34d89ba698911fd51",
 "6aa606d546ba1e8daab1a165",
 "750183fda330d0b0c443cfa9",
 nil,
 nil,
 nil,
 nil,
 nil,
 nil,
 nil,
...]
  1. Run a schedule job

On this branch, you should get a job id indicating that it is scheduled.

[7] pry(main)> Chaos::SleepWorker.perform_in(100,3)
=> "95cf5961c914b64908b50ed9"

On the master branch (run gdk restart and possibly step 3), you will get a nil, indicating that it is deferred.

[7] pry(main)> Chaos::SleepWorker.perform_in(100,3)
=> nil
Edited by Sylvester Chin

Merge request reports

Loading