51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
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()
|
|
}
|