(logger: Logger)
| 10 | }; |
| 11 | |
| 12 | async function task(logger: Logger) { |
| 13 | const domains = await prisma.accounts.findMany({ |
| 14 | select: { id: true, redirectDomain: true, redirectDomainPropagate: true }, |
| 15 | where: { redirectDomain: { not: null } }, |
| 16 | }); |
| 17 | logger.info({ domains: domains.length }); |
| 18 | |
| 19 | const promises = domains.map(async (account) => { |
| 20 | if (account.redirectDomain) { |
| 21 | const res = await axios |
| 22 | .head(`https://${account.redirectDomain}/api/health`) |
| 23 | .catch((e) => { |
| 24 | return { status: 500 }; |
| 25 | }); |
| 26 | // it was ok, now isn't |
| 27 | if (res.status !== 200 && !!account.redirectDomainPropagate) { |
| 28 | await prisma.accounts.update({ |
| 29 | where: { id: account.id }, |
| 30 | data: { redirectDomainPropagate: false }, |
| 31 | }); |
| 32 | // probably new domain, is ok, it is mark as propagate |
| 33 | } else if (res.status === 200 && !account.redirectDomainPropagate) { |
| 34 | await prisma.accounts.update({ |
| 35 | where: { id: account.id }, |
| 36 | data: { redirectDomainPropagate: true }, |
| 37 | }); |
| 38 | } |
| 39 | } |
| 40 | }); |
| 41 | await Promise.allSettled(promises); |
| 42 | } |
no test coverage detected