cli.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class BackgroundServices
  3. class Cli < ::Thor
  4. # rubocop:disable Zammad/DetectTranslatableString
  5. def self.exit_on_failure?
  6. # Signal to Thor API that failures should be reflected in the exit code.
  7. true
  8. end
  9. desc 'start', 'Execute background services.'
  10. def start
  11. config = BackgroundServices::ServiceConfig.configuration_from_env(ENV)
  12. if %w[1 true].include? ENV['BACKGROUND_SERVICES_LOG_TO_STDOUT']
  13. Zammad::Logging.extend_logging_to_stdout
  14. elsif Rails.env.development?
  15. puts 'BackgroundServices do not log to STDOUT. You can enable this by setting BACKGROUND_SERVICES_LOG_TO_STDOUT=1.' # rubocop:disable Rails/Output
  16. end
  17. BackgroundServices.new(config).run
  18. end
  19. def self.help(shell, subcommand = nil)
  20. super
  21. shell.say 'Startup behaviour can be customized with these environment variables:'
  22. shell.say
  23. list = [
  24. ['Service', 'Set worker count', 'Max. workers', 'Disable this service'],
  25. ['-------', '----------------', '------------', '--------------------'],
  26. ]
  27. BackgroundServices.available_services.each do |service|
  28. service_name = service.name.demodulize
  29. env_prefix = "ZAMMAD_#{service_name.underscore.upcase}"
  30. list.push [service_name, "#{env_prefix}_WORKERS", service.max_workers, "#{env_prefix}_DISABLE"]
  31. end
  32. shell.print_table(list, indent: 2)
  33. shell.say
  34. shell.say 'For more information, please see https://docs.zammad.org/en/latest/appendix/configure-env-vars.html.'
  35. end
  36. # rubocop:enable Zammad/DetectTranslatableString
  37. end
  38. end