no cluster unless in k8s, fix credo issues

This commit is contained in:
Graham McIntire 2026-02-09 13:08:51 -06:00
parent 94bcf8ac4e
commit f8d2570bb3
No known key found for this signature in database
4 changed files with 30 additions and 19 deletions

View file

@ -118,7 +118,9 @@
#
## Refactoring Opportunities
#
{Credo.Check.Refactor.Apply, []},
# Disabled: We intentionally use apply/3 for optional dev-only dependencies
# to avoid compile-time warnings in production builds
# {Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FilterCount, []},

View file

@ -92,18 +92,27 @@ if config_env() == :prod do
false
end
config :libcluster,
topologies: [
k8s: [
strategy: Cluster.Strategy.Kubernetes.DNS,
config: [
service: "towerops-headless",
application_name: "towerops",
namespace: "towerops",
polling_interval: 10_000
# Only enable libcluster in Kubernetes deployments
# Kubernetes automatically sets KUBERNETES_SERVICE_HOST env var
libcluster_topologies =
if System.get_env("KUBERNETES_SERVICE_HOST") do
[
k8s: [
strategy: Cluster.Strategy.Kubernetes.DNS,
config: [
service: "towerops-headless",
application_name: "towerops",
namespace: "towerops",
polling_interval: 10_000
]
]
]
]
else
# No clustering for non-K8s deployments (Dokku, single-node, etc.)
[]
end
config :libcluster, topologies: libcluster_topologies
# Configure Swoosh to use Req for API requests
config :swoosh, :api_client, Swoosh.ApiClient.Req

View file

@ -224,9 +224,9 @@ defmodule Towerops.Application do
# Register file logger backend for development (only available in :dev environment)
defp register_file_logger do
if Code.ensure_loaded?(LoggerBackends) do
# Add the backend with a unique identifier
LoggerBackends.add({LoggerFileBackend, :file_log})
if Code.ensure_loaded?(LoggerBackends) and Code.ensure_loaded?(LoggerFileBackend) do
# Add the backend with a unique identifier (using apply to avoid compile-time warnings)
apply(LoggerBackends, :add, [{LoggerFileBackend, :file_log}])
# Configure the backend with path and level
Logger.configure_backend({LoggerFileBackend, :file_log},
@ -234,7 +234,7 @@ defmodule Towerops.Application do
level: :debug
)
else
Logger.warning("LoggerBackends not available - file logging disabled")
Logger.debug("LoggerBackends not available - file logging disabled (dev-only feature)")
end
end

View file

@ -28,16 +28,16 @@ defmodule Towerops.Profiles.ProfileWatcher do
# Get the absolute path to the profiles directory
profiles_path = Path.join(Application.app_dir(:towerops), @profiles_dir)
# Start watching the profiles directory for changes
{:ok, watcher_pid} = FileSystem.start_link(dirs: [profiles_path])
FileSystem.subscribe(watcher_pid)
# Start watching the profiles directory for changes (using apply to avoid compile-time warnings)
{:ok, watcher_pid} = apply(FileSystem, :start_link, [[dirs: [profiles_path]]])
apply(FileSystem, :subscribe, [watcher_pid])
Logger.info("ProfileWatcher: Started watching #{profiles_path}")
{:ok, %{watcher_pid: watcher_pid, profiles_path: profiles_path}}
else
# In production, FileSystem is not available
Logger.debug("ProfileWatcher: FileSystem not available, running in no-op mode")
Logger.debug("ProfileWatcher: FileSystem not available, running in no-op mode (dev-only feature)")
{:ok, %{}}
end
end