Merged in feature/warmup (pull request #1887)
* unified warmup function Approved-by: Linus Flood
This commit is contained in:
50
apps/scandic-web/services/warmup/index.ts
Normal file
50
apps/scandic-web/services/warmup/index.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { Lang } from "@/constants/languages"
|
||||
|
||||
import { warmupCountry } from "./warmupCountries"
|
||||
import { warmupHotelData } from "./warmupHotelData"
|
||||
import { warmupHotelIdsByCountry } from "./warmupHotelIdsByCountry"
|
||||
|
||||
import type { WarmupFunctionsKey } from "./warmupKeys"
|
||||
|
||||
export type WarmupFunction = () => Promise<WarmupResult>
|
||||
|
||||
type BaseWarmup = {
|
||||
status: "skipped" | "completed"
|
||||
}
|
||||
|
||||
type FailedWarmup = {
|
||||
status: "error"
|
||||
error: Error
|
||||
}
|
||||
|
||||
export type WarmupResult = BaseWarmup | FailedWarmup
|
||||
|
||||
export const warmupFunctions: Record<WarmupFunctionsKey, WarmupFunction> = {
|
||||
countries_en: warmupCountry(Lang.en),
|
||||
countries_da: warmupCountry(Lang.da),
|
||||
countries_de: warmupCountry(Lang.de),
|
||||
countries_fi: warmupCountry(Lang.fi),
|
||||
countries_sv: warmupCountry(Lang.sv),
|
||||
countries_no: warmupCountry(Lang.no),
|
||||
|
||||
hotelsByCountry: warmupHotelIdsByCountry(),
|
||||
|
||||
hotelData_en: warmupHotelData(Lang.en),
|
||||
hotelData_da: warmupHotelData(Lang.da),
|
||||
hotelData_de: warmupHotelData(Lang.de),
|
||||
hotelData_fi: warmupHotelData(Lang.fi),
|
||||
hotelData_sv: warmupHotelData(Lang.sv),
|
||||
hotelData_no: warmupHotelData(Lang.no),
|
||||
}
|
||||
|
||||
export async function warmup(key: WarmupFunctionsKey): Promise<WarmupResult> {
|
||||
const func = warmupFunctions[key]
|
||||
if (!func) {
|
||||
return {
|
||||
status: "error",
|
||||
error: new Error(`Warmup function ${key} not found`),
|
||||
}
|
||||
}
|
||||
|
||||
return func()
|
||||
}
|
||||
Reference in New Issue
Block a user