l4d.tools/app/jobs/spawn_server_job.rb
2026-01-18 17:42:32 +01:00

21 lines
660 B
Ruby

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