Move NCMall and NeoPass services into a Neopets module
Just a bit more clarity of grouping! I'm also thinking about extracting modeling APIs into a service file like this too, in which case I think this would help clarify what it is.
This commit is contained in:
parent
7ef689d658
commit
acb52cb870
5 changed files with 8 additions and 8 deletions
|
@ -161,7 +161,7 @@ class AuthUser < AuthRecord
|
||||||
# means we can wrap it in a `with_timeout` block!)
|
# means we can wrap it in a `with_timeout` block!)
|
||||||
neopets_username = Sync do |task|
|
neopets_username = Sync do |task|
|
||||||
task.with_timeout(5) do
|
task.with_timeout(5) do
|
||||||
NeoPass.load_main_neopets_username(auth.credentials.token)
|
Neopets::NeoPass.load_main_neopets_username(auth.credentials.token)
|
||||||
end
|
end
|
||||||
rescue Async::TimeoutError
|
rescue Async::TimeoutError
|
||||||
nil # If the request times out, just move on!
|
nil # If the request times out, just move on!
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
require "addressable/template"
|
require "addressable/template"
|
||||||
require "async/http/internet/instance"
|
require "async/http/internet/instance"
|
||||||
|
|
||||||
module NCMall
|
module Neopets::NCMall
|
||||||
# Share a pool of persistent connections, rather than reconnecting on
|
# Share a pool of persistent connections, rather than reconnecting on
|
||||||
# each request. (This library does that automatically!)
|
# each request. (This library does that automatically!)
|
||||||
INTERNET = Async::HTTP::Internet.instance
|
INTERNET = Async::HTTP::Internet.instance
|
|
@ -2,7 +2,7 @@ require "async/http/internet/instance"
|
||||||
|
|
||||||
# While most of our NeoPass logic is built into Devise -> OmniAuth -> OIDC
|
# While most of our NeoPass logic is built into Devise -> OmniAuth -> OIDC
|
||||||
# OmniAuth plugin, NeoPass also offers some supplemental APIs that we use here.
|
# OmniAuth plugin, NeoPass also offers some supplemental APIs that we use here.
|
||||||
module NeoPass
|
module Neopets::NeoPass
|
||||||
# Share a pool of persistent connections, rather than reconnecting on
|
# Share a pool of persistent connections, rather than reconnecting on
|
||||||
# each request. (This library does that automatically!)
|
# each request. (This library does that automatically!)
|
||||||
INTERNET = Async::HTTP::Internet.instance
|
INTERNET = Async::HTTP::Internet.instance
|
|
@ -19,10 +19,10 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
# Teach Zeitwerk that `RocketAMF` is what to expect in `lib/rocketamf`.
|
# Teach Zeitwerk that `RocketAMF` is what to expect in `lib/rocketamf`.
|
||||||
inflect.acronym "RocketAMF"
|
inflect.acronym "RocketAMF"
|
||||||
|
|
||||||
# Teach Zeitwerk that `NeoPass` is what to expect in `app/services/neopass.rb`.
|
# Teach Zeitwerk that `NeoPass` is what to expect in `neopass.rb`.
|
||||||
inflect.acronym "NeoPass"
|
inflect.acronym "NeoPass"
|
||||||
|
|
||||||
# Teach Zeitwerk that "NCMall" is what to expect in `app/services/nc_mall.rb`.
|
# Teach Zeitwerk that "NCMall" is what to expect in `nc_mall.rb`.
|
||||||
# (We do this by teaching it the word "NC".)
|
# (We do this by teaching it the word "NC".)
|
||||||
inflect.acronym "NC"
|
inflect.acronym "NC"
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,17 +77,17 @@ end
|
||||||
def load_all_nc_mall_pages
|
def load_all_nc_mall_pages
|
||||||
Sync do
|
Sync do
|
||||||
# First, start loading the homepage.
|
# First, start loading the homepage.
|
||||||
homepage_task = Async { NCMall.load_home_page }
|
homepage_task = Async { Neopets::NCMall.load_home_page }
|
||||||
|
|
||||||
# Next, load the page links for different categories etc.
|
# Next, load the page links for different categories etc.
|
||||||
links = NCMall.load_page_links
|
links = Neopets::NCMall.load_page_links
|
||||||
|
|
||||||
# Next, load the linked pages, 10 at a time.
|
# Next, load the linked pages, 10 at a time.
|
||||||
barrier = Async::Barrier.new
|
barrier = Async::Barrier.new
|
||||||
semaphore = Async::Semaphore.new(10, parent: barrier)
|
semaphore = Async::Semaphore.new(10, parent: barrier)
|
||||||
begin
|
begin
|
||||||
linked_page_tasks = links.map do |link|
|
linked_page_tasks = links.map do |link|
|
||||||
semaphore.async { NCMall.load_page link[:type], link[:cat] }
|
semaphore.async { Neopets::NCMall.load_page link[:type], link[:cat] }
|
||||||
end
|
end
|
||||||
barrier.wait # Load all the pages.
|
barrier.wait # Load all the pages.
|
||||||
ensure
|
ensure
|
||||||
|
|
Loading…
Reference in a new issue