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"
|
minute: "*/10"
|
||||||
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails nc_mall:sync'"
|
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
|
become_user: impress
|
||||||
cron:
|
cron:
|
||||||
name: "Impress: import NC Mall data"
|
name: "Impress: import Neopets data"
|
||||||
minute: "*/10"
|
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`
|
- name: Create weekly cron job to run `rails public_data:commit`
|
||||||
become_user: impress
|
become_user: impress
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,27 @@ namespace :neopets do
|
||||||
]
|
]
|
||||||
|
|
||||||
namespace :import 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
|
task :neologin do
|
||||||
unless Neologin.cookie?
|
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: ")
|
Neologin.cookie = STDIN.getpass("Neologin cookie: ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
namespace "neopets:import" do
|
namespace "neopets:import" do
|
||||||
desc "Sync our NCMallRecord table with the live NC Mall"
|
desc "Sync our NCMallRecord table with the live NC Mall"
|
||||||
task :nc_mall => :environment do
|
task :nc_mall => :environment do
|
||||||
|
begin
|
||||||
# Log to STDOUT.
|
# Log to STDOUT.
|
||||||
Rails.logger = Logger.new(STDOUT)
|
Rails.logger = Logger.new(STDOUT)
|
||||||
|
|
||||||
|
|
@ -72,6 +73,12 @@ namespace "neopets:import" do
|
||||||
"item #{item_name}: #{record.inspect}"
|
"item #{item_name}: #{record.inspect}"
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ require "addressable/template"
|
||||||
namespace "neopets:import" do
|
namespace "neopets:import" do
|
||||||
desc "Import all basic image hashes from the Rainbow Pool, onto PetTypes"
|
desc "Import all basic image hashes from the Rainbow Pool, onto PetTypes"
|
||||||
task :rainbow_pool => ["neopets:import:neologin", :environment] do
|
task :rainbow_pool => ["neopets:import:neologin", :environment] do
|
||||||
|
begin
|
||||||
puts "Importing from Rainbow Pool…"
|
puts "Importing from Rainbow Pool…"
|
||||||
|
|
||||||
all_species = Species.order(:name).to_a
|
all_species = Species.order(:name).to_a
|
||||||
|
|
@ -24,6 +25,9 @@ namespace "neopets:import" do
|
||||||
RainbowPool.load_hashes_for_species(species.id, Neologin.cookie)
|
RainbowPool.load_hashes_for_species(species.id, Neologin.cookie)
|
||||||
rescue => error
|
rescue => error
|
||||||
puts "Failed to load #{species.name} page, skipping: #{error.message}"
|
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
|
end
|
||||||
num_loaded += 1
|
num_loaded += 1
|
||||||
print "\r#{num_loaded}/#{num_total} species loaded"
|
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 " +
|
puts "Saved #{changed_pet_types.size} image hashes for " +
|
||||||
"#{species.human_name}"
|
"#{species.human_name}"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
namespace "neopets:import" do
|
namespace "neopets:import" do
|
||||||
desc "Import alt style info from the NC Styling Studio"
|
desc "Import alt style info from the NC Styling Studio"
|
||||||
task :styling_studio => ["neopets:import:neologin", :environment] do
|
task :styling_studio => ["neopets:import:neologin", :environment] do
|
||||||
|
begin
|
||||||
puts "Importing from Styling Studio…"
|
puts "Importing from Styling Studio…"
|
||||||
|
|
||||||
all_species = Species.order(:name).to_a
|
all_species = Species.order(:name).to_a
|
||||||
|
|
@ -21,6 +22,9 @@ namespace "neopets:import" do
|
||||||
)
|
)
|
||||||
rescue => error
|
rescue => error
|
||||||
puts "\n⚠️ Error loading for #{species.human_name}, skipping: #{error.message}"
|
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
|
end
|
||||||
num_loaded += 1
|
num_loaded += 1
|
||||||
print "\r#{num_loaded}/#{num_total} species loaded"
|
print "\r#{num_loaded}/#{num_total} species loaded"
|
||||||
|
|
@ -95,5 +99,11 @@ namespace "neopets:import" do
|
||||||
puts "#{species.human_name}: #{counts[:changed]} changed, " +
|
puts "#{species.human_name}: #{counts[:changed]} changed, " +
|
||||||
"#{counts[:unchanged]} unchanged, #{counts[:skipped]} skipped"
|
"#{counts[:unchanged]} unchanged, #{counts[:skipped]} skipped"
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue