discourse/config/initializers/000-zeitwerk.rb
Loïc Guitaut 6b243ffdfd
DEV: Remove Unicorn web server in favor of Pitchfork (#39032)
Pitchfork has been the default web server for some time now. This
removes Unicorn entirely to simplify the codebase and unblock future
improvements (like Rack 3).

Notable changes beyond the straightforward removal:

- `Discourse.after_unicorn_worker_fork` →
`Discourse.apply_worker_db_variables_overrides`: renamed and wired into
pitchfork.conf.rb's `after_worker_fork`. This actually *fixes*
per-worker DB variable overrides (`unicorn_worker_db_variables_*`) which
were never called under Pitchfork.
- `bin/ember-cli`: `--unicorn` flag renamed to `--server` (`-u` kept).
- `lib/demon/sidekiq.rb`: removed Unicorn-specific USR1/USR2 signal
handlers and `reopen_logs` (called `Unicorn::Util.reopen_logs`), which
were already dead code under Pitchfork.

Intentionally kept unchanged:
- `config/unicorn_launcher` (used by Docker images, separate effort)
- `docker_manager` plugin (separate repo)
- `UNICORN_*` env vars (renaming deferred)
- Rack < 3 constraint (separate PR)
2026-04-01 15:04:59 +02:00

62 lines
2.1 KiB
Ruby

# frozen_string_literal: true
# This custom inflector is needed because of our jobs directory structure.
# Ideally, we should not prefix our jobs with a `Jobs` namespace but instead
# have a `Job` suffix to follow the Rails conventions on naming.
#
# Based on:
# https://github.com/rails/rails/blob/75e6c0ac/railties/lib/rails/autoloaders/inflector.rb#L7-L19
module DiscourseInflector
@overrides = {}
def self.camelize(basename, abspath)
return basename.camelize if abspath.ends_with?("onceoff.rb")
return "Jobs" if abspath.ends_with?("jobs/base.rb")
@overrides[basename] || basename.camelize
end
def self.inflect(overrides)
@overrides.merge!(overrides)
end
end
Rails.autoloaders.each do |autoloader|
autoloader.inflector = DiscourseInflector
# We have filenames that do not follow Zeitwerk's camelization convention. Maintain an inflections for these files
# for now until we decide to fix them one day.
autoloader.inflector.inflect(
"canonical_url" => "CanonicalURL",
"clean_up_unmatched_ips" => "CleanUpUnmatchedIPs",
"homepage_constraint" => "HomePageConstraint",
"ip_addr" => "IPAddr",
"onpdiff" => "ONPDiff",
"pop3_polling_enabled_setting_validator" => "POP3PollingEnabledSettingValidator",
"version" => "Discourse",
"onceoff" => "Jobs",
"regular" => "Jobs",
"scheduled" => "Jobs",
"google_oauth2_authenticator" => "GoogleOAuth2Authenticator",
"omniauth_strategies" => "OmniAuthStrategies",
"csrf_token_verifier" => "CSRFTokenVerifier",
"html" => "HTML",
"json" => "JSON",
"ssrf_detector" => "SSRFDetector",
"http" => "HTTP",
"oauth_client_registration" => "OAuthClientRegistration",
"oauth_discovery" => "OAuthDiscovery",
"oauth_flow" => "OAuthFlow",
"oauth_token_store" => "OAuthTokenStore",
"gc_stat_instrumenter" => "GCStatInstrumenter",
"chat_sdk" => "ChatSDK",
"ip" => "IP",
)
end
Rails.autoloaders.main.ignore(
"lib/tasks",
"lib/generators",
"lib/freedom_patches",
"lib/i18n/backend",
"lib/release_utils",
"lib/pitchfork_logstash_patch.rb",
)