Skip to content

Commit

Permalink
style(monitorin): cleaner style
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed May 24, 2024
1 parent eaa3763 commit d1fa7ea
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions src/monitoring/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import dns from "dns/promises"

import { retry } from "@octokit/plugin-retry"
import { Octokit } from "@octokit/rest"
import autoBind from "auto-bind"
import axios from "axios"
import _ from "lodash"
import { errAsync, okAsync, ResultAsync } from "neverthrow"

import parentLogger from "@logger/logger"
Expand Down Expand Up @@ -32,12 +34,6 @@ type keyCdnZoneAlias = {
name: string
}

interface KeyCdnResponse {
data: {
zonealiases: keyCdnZoneAlias[]
}
}

interface RedirectionDomain {
source: string
target: string
Expand Down Expand Up @@ -116,8 +112,11 @@ export default class MonitoringService {
*/
getRedirectionDomains() {
const SYSTEM_GITHUB_TOKEN = config.get("github.systemToken")
const OctokitRetry = Octokit.plugin()
const octokitWithRetry = new OctokitRetry({
// seems to be a bug in typing, this is a direct
// copy paste from the octokit documentation
// https://octokit.github.io/rest.js/v20#automatic-retries
const OctokitRetry = Octokit.plugin(retry as any)
const octokitWithRetry: Octokit = new OctokitRetry({
auth: SYSTEM_GITHUB_TOKEN,
request: { retries: 5 },
})
Expand Down Expand Up @@ -164,25 +163,9 @@ export default class MonitoringService {
]).andThen(([amplifyDeployments, redirectionDomains, keyCdnDomains]) => {
this.monitoringServiceLogger.info("Fetched all domains")
return okAsync(
[...amplifyDeployments, ...redirectionDomains, ...keyCdnDomains].sort(
(a, b) => {
const domainA = a.domain
const domainB = b.domain
if (
domainA.startsWith("www.") &&
domainA.slice(`www.`.length) === domainB
) {
return 0
}
if (
domainB.startsWith("www.") &&
domainA === domainB.slice(`www.`.length)
) {
return 0
}
if (domainA === domainB) return 0
return domainA > domainB ? 1 : -1
}
_.sortBy(
[...amplifyDeployments, ...redirectionDomains, ...keyCdnDomains],
(val) => (val.domain.startsWith("www.") ? val.domain.slice(4) : val)
)
)
})
Expand Down

0 comments on commit d1fa7ea

Please sign in to comment.