Class MenuItemsLoader
java.lang.Object
edu.ucsb.cs156.dining.services.MenuItemsLoader
Downloads every MenuItem for the current month from the UCSB Dining API and stores them in the
database. Intended to be called once at startup, so that users don't depend on someone having
visited a given day's menu for its items to exist.
Requests that get an HTTP 429 (Too Many Requests) are retried with exponential backoff
(honoring a Retry-After header when present). If the retries are exhausted, the whole
load stops rather than continuing to hammer the API. If the API key is not configured, no
requests are sent at all.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final intstatic final longstatic final StringThe default value of app.ucsb.api.consumer_key when UCSB_API_KEY has not been set. -
Constructor Summary
ConstructorsConstructorDescriptionMenuItemsLoader(DiningCommonsService diningCommonsService, UCSBDiningMenuService menuService, UCSBDiningMenuItemsService menuItemsService, com.fasterxml.jackson.databind.ObjectMapper objectMapper, String apiKey) -
Method Summary
Modifier and TypeMethodDescriptionvoidLoads all MenuItems for every day of the current month, for every dining commons.
-
Field Details
-
PLACEHOLDER_API_KEY
The default value of app.ucsb.api.consumer_key when UCSB_API_KEY has not been set.- See Also:
-
MAX_ATTEMPTS
public static final int MAX_ATTEMPTS- See Also:
-
BASE_BACKOFF_MS
public static final long BASE_BACKOFF_MS- See Also:
-
MAX_BACKOFF_MS
public static final long MAX_BACKOFF_MS- See Also:
-
-
Constructor Details
-
MenuItemsLoader
public MenuItemsLoader(DiningCommonsService diningCommonsService, UCSBDiningMenuService menuService, UCSBDiningMenuItemsService menuItemsService, com.fasterxml.jackson.databind.ObjectMapper objectMapper, @Value("${app.ucsb.api.consumer_key}") String apiKey)
-
-
Method Details
-
loadCurrentMonth
public void loadCurrentMonth()Loads all MenuItems for every day of the current month, for every dining commons. Never throws: problems are logged.
-