sidekiq.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # frozen_string_literal: true
  2. require_relative '../../lib/mastodon/sidekiq_middleware'
  3. Sidekiq.configure_server do |config|
  4. config.redis = REDIS_CONFIGURATION.sidekiq
  5. # This is used in Kubernetes setups, to signal that the Sidekiq process has started and will begin processing jobs
  6. # This comes from https://github.com/sidekiq/sidekiq/wiki/Kubernetes#sidekiq
  7. ready_filename = ENV.fetch('MASTODON_SIDEKIQ_READY_FILENAME', nil)
  8. if ready_filename
  9. raise 'MASTODON_SIDEKIQ_READY_FILENAME is not a valid filename' if File.basename(ready_filename) != ready_filename
  10. ready_path = Rails.root.join('tmp', ready_filename)
  11. config.on(:startup) do
  12. FileUtils.touch(ready_path)
  13. end
  14. config.on(:shutdown) do
  15. FileUtils.rm_f(ready_path)
  16. end
  17. end
  18. config.server_middleware do |chain|
  19. chain.add Mastodon::SidekiqMiddleware
  20. end
  21. config.server_middleware do |chain|
  22. chain.add SidekiqUniqueJobs::Middleware::Server
  23. end
  24. config.client_middleware do |chain|
  25. chain.add SidekiqUniqueJobs::Middleware::Client
  26. end
  27. config.on(:startup) do
  28. if SelfDestructHelper.self_destruct?
  29. Sidekiq.schedule = {
  30. 'self_destruct_scheduler' => {
  31. 'interval' => ['1m'],
  32. 'class' => 'Scheduler::SelfDestructScheduler',
  33. 'queue' => 'scheduler',
  34. },
  35. }
  36. SidekiqScheduler::Scheduler.instance.reload_schedule!
  37. end
  38. end
  39. SidekiqUniqueJobs::Server.configure(config)
  40. end
  41. Sidekiq.configure_client do |config|
  42. config.redis = REDIS_CONFIGURATION.sidekiq
  43. config.client_middleware do |chain|
  44. chain.add SidekiqUniqueJobs::Middleware::Client
  45. end
  46. end
  47. Sidekiq.logger.level = ::Logger.const_get(ENV.fetch('RAILS_LOG_LEVEL', 'info').upcase.to_s)
  48. SidekiqUniqueJobs.configure do |config|
  49. config.enabled = !Rails.env.test?
  50. config.reaper = :ruby
  51. config.reaper_count = 1000
  52. config.reaper_interval = 600
  53. config.reaper_timeout = 150
  54. config.lock_ttl = 50.days.to_i
  55. end