manage_sessions_jobs.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class BackgroundServices
  3. class Service
  4. class ManageSessionsJobs < Service
  5. def self.max_workers
  6. 1
  7. end
  8. # This service is only needed when we have forked ProcessSessionJobs running,
  9. # to coordinate the sessions between the different processes.
  10. def self.skip?(manager:)
  11. session_jobs_config = manager.config.find { |elem| elem.service == BackgroundServices::Service::ProcessSessionsJobs }
  12. !session_jobs_config || session_jobs_config.disabled || session_jobs_config.start_as != :fork
  13. end
  14. def launch
  15. loop do
  16. break if BackgroundServices.shutdown_requested
  17. single_run
  18. sleep 1
  19. end
  20. end
  21. private
  22. def single_run
  23. nodes_stats = Sessions::Node.stats
  24. Sessions
  25. .sessions
  26. .each do |client_id|
  27. # ask nodes for nodes
  28. next if nodes_stats[client_id]
  29. # assign to node
  30. Sessions::Node.session_assigne(client_id)
  31. sleep 1
  32. end
  33. end
  34. end
  35. end
  36. end