class SpawnServerJob < ApplicationJob queue_as :default def perform(server_id) server = Server.find(server_id) begin L4dServer::Launcher.spawn(server) server.update(status: :starting) # Generate a random RCON password for health checks server.update(rcon_password: SecureRandom.hex(16)) Activity.log(server.user, "spawned_success", "Server", server.id, { name: server.name }) rescue StandardError => e Rails.logger.error("Server spawn failed: #{e.message}") server.update(status: :failed) Activity.log(server.user, "spawn_failed", "Server", server.id, { error: e.message }) end end end