From eed24c00b8d7917ea0d9584bc3e3ffcaef3cd272 Mon Sep 17 00:00:00 2001 From: kirinnee Date: Mon, 26 Feb 2024 13:20:41 +0800 Subject: [PATCH] perf: additional logs to check wrong --- config/dev.yaml | 2 +- infra/root_chart/Chart.lock | 8 ++++---- infra/root_chart/Chart.yaml | 4 ++-- infra/root_chart/README.md | 6 +++--- infra/root_chart/values.yaml | 2 +- src/domain/search_core.ts | 17 +++++++++++++++-- src/index.ts | 2 +- 7 files changed, 27 insertions(+), 14 deletions(-) diff --git a/config/dev.yaml b/config/dev.yaml index 6d848dd..2638d14 100644 --- a/config/dev.yaml +++ b/config/dev.yaml @@ -7,7 +7,7 @@ service: helium port: 11000 # "local" or "cluster" -type: cluster +type: local # fast mode # 1. does not start the cluster, automatically assumes that your cluster already created diff --git a/infra/root_chart/Chart.lock b/infra/root_chart/Chart.lock index 1c70025..2b07065 100644 --- a/infra/root_chart/Chart.lock +++ b/infra/root_chart/Chart.lock @@ -1,12 +1,12 @@ dependencies: - name: sulfoxide-bromine repository: oci://ghcr.io/atomicloud/sulfoxide.bromine - version: 1.3.0 + version: 1.4.0 - name: root-chart repository: oci://ghcr.io/atomicloud/nitroso.zinc - version: 1.8.7 + version: 1.17.2 - name: bun-cron-chart repository: file://../cron_chart version: 0.1.0 -digest: sha256:c0b67557f5e7ff6f07cc7a380c7ce55acaf35e2513ce0faee938f5444c4d54fc -generated: "2023-12-31T11:14:29.679493+08:00" +digest: sha256:3ff9c590c293fa5bc7ddf3ff8ddb0774c68d5c719b89fca890e63ea153355d67 +generated: "2024-02-26T12:43:34.276733+08:00" diff --git a/infra/root_chart/Chart.yaml b/infra/root_chart/Chart.yaml index f92265b..dd4eefb 100644 --- a/infra/root_chart/Chart.yaml +++ b/infra/root_chart/Chart.yaml @@ -8,12 +8,12 @@ appVersion: "1.16.0" dependencies: - name: sulfoxide-bromine - version: 1.3.0 + version: 1.4.0 condition: bromine.enable alias: bromine repository: oci://ghcr.io/atomicloud/sulfoxide.bromine - name: root-chart - version: 1.8.7 + version: 1.17.2 condition: zinc.enable alias: zinc repository: oci://ghcr.io/atomicloud/nitroso.zinc diff --git a/infra/root_chart/README.md b/infra/root_chart/README.md index 71e17ea..465cc24 100644 --- a/infra/root_chart/README.md +++ b/infra/root_chart/README.md @@ -9,8 +9,8 @@ Root Chart to a single Service | Repository | Name | Version | |------------|------|---------| | file://../cron_chart | scheduler(bun-cron-chart) | 0.1.0 | -| oci://ghcr.io/atomicloud/nitroso.zinc | zinc(root-chart) | 1.8.7 | -| oci://ghcr.io/atomicloud/sulfoxide.bromine | bromine(sulfoxide-bromine) | 1.3.0 | +| oci://ghcr.io/atomicloud/nitroso.zinc | zinc(root-chart) | 1.17.2 | +| oci://ghcr.io/atomicloud/sulfoxide.bromine | bromine(sulfoxide-bromine) | 1.4.0 | ## Values @@ -42,7 +42,7 @@ Root Chart to a single Service | serviceTree.platform | string | `"nitroso"` | | | serviceTree.service | string | `"helium"` | | | zinc.api.configMountPath | string | `"/app/Config"` | | -| zinc.api.image.repository | string | `"ghcr.io/atomicloud/nitroso.zinc/api-arm"` | | +| zinc.api.image.repository | string | `"ghcr.io/atomicloud/nitroso.zinc/api"` | | | zinc.migration.enabled | bool | `false` | | ---------------------------------------------- diff --git a/infra/root_chart/values.yaml b/infra/root_chart/values.yaml index e438399..218070a 100644 --- a/infra/root_chart/values.yaml +++ b/infra/root_chart/values.yaml @@ -26,7 +26,7 @@ zinc: api: configMountPath: /app/Config image: - repository: ghcr.io/atomicloud/nitroso.zinc/api-arm + repository: ghcr.io/atomicloud/nitroso.zinc/api migration: enabled: false diff --git a/src/domain/search_core.ts b/src/domain/search_core.ts index 3d40596..aa2905c 100644 --- a/src/domain/search_core.ts +++ b/src/domain/search_core.ts @@ -4,6 +4,7 @@ import { From, TrainSchedule } from "./interface.ts"; import { stringify } from "querystring"; import moment from "moment"; import { SearcherConfig } from "../config/searcher.config.ts"; +import { Logger } from "pino"; const f = fetchCookie(fetch); @@ -62,9 +63,11 @@ interface TrainScheduleResp { class SearchCore { #config: SearcherConfig; + #logger: Logger; - constructor(config: SearcherConfig) { + constructor(config: SearcherConfig, logger: Logger) { this.#config = config; + this.#logger = logger; } async mainKTMBPage(): Promise { @@ -179,7 +182,17 @@ class SearchCore { init, ); - const obj = (await r.json()) as TrainScheduleResp; + let o: TrainScheduleResp | null = null; + const text = await r.text(); + + try { + o = JSON.parse(text); + } catch (e) { + this.#logger.error(e, "Error parsing response from KTMB", { text }); + throw e; + } + + const obj = o as TrainScheduleResp; const $ = cheerio.load(obj.data); diff --git a/src/index.ts b/src/index.ts index dc2bcb6..2d16728 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,7 +35,7 @@ const caches = loadRedis(cfg); const descope = loadDescope(cfg.auth.descope); const auth: Auth = new DescopeAuth(descope, cfg.auth.descope); const zincDate = new ZincDate(); -const searchCore = new SearchCore(cfg.app.searcher); +const searchCore = new SearchCore(cfg.app.searcher, logger); const searchBuilder = new SearcherBuilder(searchCore); const detailFactory = new DetailFactory(cfg.error, cfg.app); const utility = new Utility(detailFactory);