34 lines
1 KiB
Ruby
34 lines
1 KiB
Ruby
class SpawnServerJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(server_id)
|
|
server = Server.find(server_id)
|
|
log "Found server: #{server.name}"
|
|
|
|
begin
|
|
log "Starting server spawn process..."
|
|
L4dServer::Launcher.spawn(server)
|
|
log "Server spawned successfully"
|
|
|
|
server.update(status: :starting)
|
|
log "Server status updated to starting"
|
|
|
|
# Generate a random RCON password for health checks
|
|
rcon_password = SecureRandom.hex(16)
|
|
server.update(rcon_password: rcon_password)
|
|
log "RCON password generated and saved"
|
|
|
|
Activity.log(server.user, "spawned_success", "Server", server.id, { name: server.name })
|
|
log "Activity logged"
|
|
rescue StandardError => e
|
|
log "ERROR: Server spawn failed: #{e.message}"
|
|
log "Backtrace: #{e.backtrace.first(3).join("\n")}"
|
|
|
|
Rails.logger.error("Server spawn failed: #{e.message}")
|
|
server.update(status: :failed)
|
|
Activity.log(server.user, "spawn_failed", "Server", server.id, { error: e.message })
|
|
|
|
raise
|
|
end
|
|
end
|
|
end
|