1
0
Fork 0
forked from OpenNeo/impress

Disable modeling in production, while we investigate errors

Hmm, I think I made a mistake on `modeling_snapshot.rb:69`: I'm
assigning the *entire* `item.swf_assets` relation to *just* the assets
for the new model of it, which breaks all the other connections.

First, I'm disabling modeling. Then, I'll restore a backup. Then, I'll
write tests for that case, and fix it up!
This commit is contained in:
Emi Matchu 2024-11-06 11:54:28 -08:00
parent 5264947608
commit d82c7f817a
6 changed files with 24 additions and 4 deletions

View file

@ -1,12 +1,10 @@
class PetsController < ApplicationController
rescue_from Neopets::CustomPets::PetNotFound, with: :pet_not_found
rescue_from Neopets::CustomPets::DownloadError, with: :pet_download_error
rescue_from Pet::ModelingDisabled, with: :modeling_disabled
rescue_from Pet::UnexpectedDataFormat, with: :unexpected_data_format
def load
# Uncomment this to temporarily disable modeling for most users.
# return modeling_disabled unless user_signed_in? && current_user.admin?
raise Neopets::CustomPets::PetNotFound unless params[:name]
@pet = Pet.load(params[:name])
points = contribute(current_user, @pet)

View file

@ -4,6 +4,8 @@ class Pet < ApplicationRecord
attr_reader :items, :pet_state, :alt_style
def load!(timeout: nil)
raise ModelingDisabled unless Rails.configuration.modeling_enabled
viewer_data_hash = Neopets::CustomPets.fetch_viewer_data(name, timeout:)
use_modeling_snapshot(ModelingSnapshot.new(viewer_data_hash))
end
@ -50,5 +52,5 @@ class Pet < ApplicationRecord
end
class UnexpectedDataFormat < RuntimeError;end
class ModelingDisabled < RuntimeError;end
end

View file

@ -103,6 +103,10 @@ Rails.application.configure do
# Allow connections on Vagrant's private network.
config.web_console.permissions = '10.0.2.2'
# Allow pets to model new data. (If modeling is ever broken, disable this in
# production while we fix it!)
config.modeling_enabled = true
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
# override this with the IMPRESS_2020_ORIGIN environment variable!)
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",

View file

@ -122,6 +122,10 @@ Rails.application.configure do
# Skip DNS rebinding protection for the default health check endpoint.
# config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
# Allow pets to model new data. (If modeling is ever broken, disable this
# here while we fix it!)
config.modeling_enabled = false
# Use the live copy of Impress 2020. (Can override this with the
# IMPRESS_2020_ORIGIN environment variable!)
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",

View file

@ -62,6 +62,10 @@ Rails.application.configure do
# Raise error when a before_action's only/except options reference missing actions
config.action_controller.raise_on_missing_callback_actions = true
# Allow pets to model new data. (If modeling is ever broken, disable this in
# production while we fix it!)
config.modeling_enabled = true
# Use a local copy of Impress 2020, presumably running on port 4000. (Can
# override this with the IMPRESS_2020_ORIGIN environment variable!)
config.impress_2020_origin = ENV.fetch("IMPRESS_2020_ORIGIN",

View file

@ -448,5 +448,13 @@ RSpec.describe Pet, type: :model do
end
end
end
context "when modeling is disabled" do
before { allow(Rails.configuration).to receive(:modeling_enabled) { false } }
it("raises an error") do
expect { Pet.load("matts_bat") }.to raise_error(Pet::ModelingDisabled)
end
end
end
end