Skip to content

Commit ef40e1e

Browse files
committed
fix broken got timeout config for starlink updater
1 parent 40a75a7 commit ef40e1e

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

app.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import conditional from 'koa-conditional-get';
22
import etag from 'koa-etag';
33
import cors from 'koa2-cors';
4+
import dotenv from 'dotenv';
45
import helmet from 'koa-helmet';
56
import Koa from 'koa';
67
import bodyParser from 'koa-bodyparser';
78
import mongoose from 'mongoose';
89
import { responseTime, errors, logger } from './middleware/index.js';
910
import routes from './routes/index.js';
1011

12+
// Env init
13+
dotenv.config();
14+
1115
const app = new Koa();
1216

1317
mongoose.connect(process.env.SPACEX_MONGO, {

jobs/payloads.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default async () => {
4040
});
4141

4242
const updates = payloads.docs.map(async (payload) => {
43-
const noradId = payload.norad_ids.shift() || null;
43+
const noradId = payload.norad_ids.shift() ?? null;
4444
const specificOrbit = data.find((sat) => parseInt(sat.NORAD_CAT_ID, 10) === noradId);
4545
if (specificOrbit) {
4646
await got.patch(`${API}/payloads/${payload.id}`, {

jobs/starlink.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ export default async () => {
5353
});
5454

5555
const data = await got('https://www.space-track.org/basicspacedata/query/class/gp/OBJECT_NAME/~~STARLINK,~~TINTIN/orderby/NORAD_CAT_ID', {
56-
resolveBodyOnly: true,
5756
responseType: 'json',
58-
timeout: 480000, // 8 minutes
57+
timeout: {
58+
request: 480000, // 8 minutes
59+
},
5960
cookieJar,
6061
});
6162

62-
const starlinkSats = data.filter((sat) => /starlink|tintin/i.test(sat.OBJECT_NAME));
63+
const starlinkSats = data.body.filter((sat) => /starlink|tintin/i.test(sat.OBJECT_NAME));
6364

6465
const updates = starlinkSats.map(async (sat) => {
6566
const date = moment.utc(sat.LAUNCH_DATE, 'YYYY-MM-DD');
@@ -94,14 +95,14 @@ export default async () => {
9495
await got.patch(`${API}/starlink/${sat.NORAD_CAT_ID}`, {
9596
json: {
9697
version: starlinkVersion(
97-
launches?.docs[0]?.date_utc || null,
98-
launches?.docs[0]?.name || null,
98+
launches?.docs[0]?.date_utc ?? null,
99+
launches?.docs[0]?.name ?? null,
99100
),
100-
launch: launches?.docs[0]?.id || null,
101-
longitude: position?.lng || null,
102-
latitude: position?.lat || null,
103-
height_km: position?.height || null,
104-
velocity_kms: position?.velocity || null,
101+
launch: launches?.docs[0]?.id ?? null,
102+
longitude: position?.lng ?? null,
103+
latitude: position?.lat ?? null,
104+
height_km: position?.height ?? null,
105+
velocity_kms: position?.velocity ?? null,
105106
spaceTrack: {
106107
CCSDS_OMM_VERS: sat.CCSDS_OMM_VERS,
107108
COMMENT: sat.COMMENT,
@@ -162,6 +163,7 @@ export default async () => {
162163
await got(HEALTHCHECK);
163164
}
164165
} catch (error) {
166+
console.error(error);
165167
console.log(`Starlink Error: ${error.message}`);
166168
}
167169
};

jobs/worker.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CronJob } from 'cron';
2+
import dotenv from 'dotenv';
23
import { logger } from '../middleware/index.js';
34
import launches from './launches.js';
45
import payloads from './payloads.js';
@@ -12,6 +13,9 @@ import starlink from './starlink.js';
1213
import webcast from './webcast.js';
1314
import launchLibrary from './launch-library.js';
1415

16+
// Env init
17+
dotenv.config();
18+
1519
// Every 10 minutes
1620
const launchesJob = new CronJob('*/10 * * * *', launches);
1721

middleware/cache.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default (ttl) => async (ctx, next) => {
8181

8282
// Set cache
8383
try {
84-
if ((ctx.response.status !== 200) || !responseBody) {
84+
if ((ctx?.response?.status !== 200) || !responseBody) {
8585
return;
8686
}
8787
await redis.set(key, responseBody, 'EX', ttl);

middleware/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default async (ctx, next) => {
1212
if (err?.kind === 'ObjectId') {
1313
err.status = 404;
1414
} else {
15-
ctx.status = err.status || 500;
15+
ctx.status = err.status ?? 500;
1616
ctx.body = err.message;
1717
}
1818
}

package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"blake3": "^2.1.7",
3434
"cheerio": "^1.0.0-rc.12",
3535
"cron": "^2.0.0",
36+
"dotenv": "^16.0.1",
3637
"fuzzball": "^2.1.2",
3738
"got": "^12.1.0",
3839
"ioredis": "^5.1.0",

0 commit comments

Comments
 (0)