diff options
Diffstat (limited to 'app/workers/concerns/application_worker.rb')
-rw-r--r-- | app/workers/concerns/application_worker.rb | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/workers/concerns/application_worker.rb b/app/workers/concerns/application_worker.rb index 7ab9a0c2a02..9c942228111 100644 --- a/app/workers/concerns/application_worker.rb +++ b/app/workers/concerns/application_worker.rb @@ -76,6 +76,22 @@ module ApplicationWorker get_sidekiq_options['queue'].to_s end + # Set/get which arguments can be logged and sent to Sentry. + # + # Numeric arguments are logged by default, so there is no need to + # list those. + # + # Non-numeric arguments must be listed by position, as Sidekiq + # cannot see argument names. + # + def loggable_arguments(*args) + if args.any? + @loggable_arguments = args + else + @loggable_arguments || [] + end + end + def queue_size Sidekiq::Queue.new(queue).size end @@ -84,7 +100,7 @@ module ApplicationWorker Sidekiq::Client.push_bulk('class' => self, 'args' => args_list) end - def bulk_perform_in(delay, args_list) + def bulk_perform_in(delay, args_list, batch_size: nil, batch_delay: nil) now = Time.now.to_i schedule = now + delay.to_i @@ -92,7 +108,14 @@ module ApplicationWorker raise ArgumentError, _('The schedule time must be in the future!') end - Sidekiq::Client.push_bulk('class' => self, 'args' => args_list, 'at' => schedule) + if batch_size && batch_delay + args_list.each_slice(batch_size.to_i).with_index do |args_batch, idx| + batch_schedule = schedule + idx * batch_delay.to_i + Sidekiq::Client.push_bulk('class' => self, 'args' => args_batch, 'at' => batch_schedule) + end + else + Sidekiq::Client.push_bulk('class' => self, 'args' => args_list, 'at' => schedule) + end end end end |