Add more importing to cron
We're gonna try saving a neologin cookie in the environment variables, and see how long-lived it is.
This commit is contained in:
parent
3dca3fe05a
commit
59da1fa04d
5 changed files with 245 additions and 201 deletions
|
|
@ -449,12 +449,12 @@
|
|||
minute: "*/10"
|
||||
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails nc_mall:sync'"
|
||||
|
||||
- name: Create 10min cron job to run `rails neopets:import:nc_mall`
|
||||
- name: Create 10min cron job to run `rails neopets:import`
|
||||
become_user: impress
|
||||
cron:
|
||||
name: "Impress: import NC Mall data"
|
||||
name: "Impress: import Neopets data"
|
||||
minute: "*/10"
|
||||
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails neopets:import:nc_mall'"
|
||||
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails neopets:import'"
|
||||
|
||||
- name: Create weekly cron job to run `rails public_data:commit`
|
||||
become_user: impress
|
||||
|
|
|
|||
|
|
@ -22,10 +22,27 @@ namespace :neopets do
|
|||
]
|
||||
|
||||
namespace :import do
|
||||
# Gets the neologin cookie, either from ENV['NEOLOGIN_COOKIE'] or by prompting.
|
||||
# The neologin cookie is required for authenticated Neopets requests (Rainbow Pool,
|
||||
# Styling Studio). It's generally long-lived (~1 year), so it can be stored in the
|
||||
# environment and rotated manually when it expires.
|
||||
#
|
||||
# To extract the cookie:
|
||||
# 1. Log into Neopets.com in your browser
|
||||
# 2. Open browser DevTools > Application/Storage > Cookies
|
||||
# 3. Find the "neologin" cookie value
|
||||
# 4. Set NEOLOGIN_COOKIE environment variable to that value
|
||||
# 5. Update production.env and redeploy when the cookie expires
|
||||
task :neologin do
|
||||
unless Neologin.cookie?
|
||||
# Try environment variable first (for automated cron jobs)
|
||||
if ENV['NEOLOGIN_COOKIE'].present?
|
||||
Neologin.cookie = ENV['NEOLOGIN_COOKIE']
|
||||
else
|
||||
# Fall back to interactive prompt (for local development)
|
||||
Neologin.cookie = STDIN.getpass("Neologin cookie: ")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
namespace "neopets:import" do
|
||||
desc "Sync our NCMallRecord table with the live NC Mall"
|
||||
task :nc_mall => :environment do
|
||||
begin
|
||||
# Log to STDOUT.
|
||||
Rails.logger = Logger.new(STDOUT)
|
||||
|
||||
|
|
@ -72,6 +73,12 @@ namespace "neopets:import" do
|
|||
"item #{item_name}: #{record.inspect}"
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
Rails.logger.error "Failed to import NC Mall data: #{e.message}"
|
||||
Rails.logger.error e.backtrace.join("\n")
|
||||
Sentry.capture_exception(e, tags: { task: "neopets:import:nc_mall" })
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ require "addressable/template"
|
|||
namespace "neopets:import" do
|
||||
desc "Import all basic image hashes from the Rainbow Pool, onto PetTypes"
|
||||
task :rainbow_pool => ["neopets:import:neologin", :environment] do
|
||||
begin
|
||||
puts "Importing from Rainbow Pool…"
|
||||
|
||||
all_species = Species.order(:name).to_a
|
||||
|
|
@ -24,6 +25,9 @@ namespace "neopets:import" do
|
|||
RainbowPool.load_hashes_for_species(species.id, Neologin.cookie)
|
||||
rescue => error
|
||||
puts "Failed to load #{species.name} page, skipping: #{error.message}"
|
||||
Sentry.capture_exception(error,
|
||||
tags: { task: "neopets:import:rainbow_pool" },
|
||||
contexts: { species: { name: species.name, id: species.id } })
|
||||
end
|
||||
num_loaded += 1
|
||||
print "\r#{num_loaded}/#{num_total} species loaded"
|
||||
|
|
@ -69,6 +73,12 @@ namespace "neopets:import" do
|
|||
puts "Saved #{changed_pet_types.size} image hashes for " +
|
||||
"#{species.human_name}"
|
||||
end
|
||||
rescue => e
|
||||
puts "Failed to import Rainbow Pool data: #{e.message}"
|
||||
puts e.backtrace.join("\n")
|
||||
Sentry.capture_exception(e, tags: { task: "neopets:import:rainbow_pool" })
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
namespace "neopets:import" do
|
||||
desc "Import alt style info from the NC Styling Studio"
|
||||
task :styling_studio => ["neopets:import:neologin", :environment] do
|
||||
begin
|
||||
puts "Importing from Styling Studio…"
|
||||
|
||||
all_species = Species.order(:name).to_a
|
||||
|
|
@ -21,6 +22,9 @@ namespace "neopets:import" do
|
|||
)
|
||||
rescue => error
|
||||
puts "\n⚠️ Error loading for #{species.human_name}, skipping: #{error.message}"
|
||||
Sentry.capture_exception(error,
|
||||
tags: { task: "neopets:import:styling_studio" },
|
||||
contexts: { species: { name: species.human_name, id: species.id } })
|
||||
end
|
||||
num_loaded += 1
|
||||
print "\r#{num_loaded}/#{num_total} species loaded"
|
||||
|
|
@ -95,5 +99,11 @@ namespace "neopets:import" do
|
|||
puts "#{species.human_name}: #{counts[:changed]} changed, " +
|
||||
"#{counts[:unchanged]} unchanged, #{counts[:skipped]} skipped"
|
||||
end
|
||||
rescue => e
|
||||
puts "Failed to import Styling Studio data: #{e.message}"
|
||||
puts e.backtrace.join("\n")
|
||||
Sentry.capture_exception(e, tags: { task: "neopets:import:styling_studio" })
|
||||
raise
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue