Skip to content

Commit

Permalink
pass api url into jobs from env
Browse files Browse the repository at this point in the history
jakewmeyer committed Jan 16, 2021
1 parent 9d20554 commit 10f4f56
Showing 14 changed files with 73 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15.2.1
15.6.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2017-2020 Jake Meyer
Copyright 2017-2021 Jake Meyer

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
10 changes: 5 additions & 5 deletions jobs/capsules.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got');
const { logger } = require('../middleware/logger');

const SPACEX_API = 'https://api.spacexdata.com/v4';
const API = process.env.SPACEX_API;
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.CAPSULES_HEALTHCHECK;

@@ -11,7 +11,7 @@ const HEALTHCHECK = process.env.CAPSULES_HEALTHCHECK;
*/
module.exports = async () => {
try {
const capsules = await got.post(`${SPACEX_API}/capsules/query`, {
const capsules = await got.post(`${API}/capsules/query`, {
json: {
options: {
pagination: false,
@@ -22,7 +22,7 @@ module.exports = async () => {
});

const updates = capsules.docs.map(async (capsule) => {
const waterLandings = await got.post(`${SPACEX_API}/payloads/query`, {
const waterLandings = await got.post(`${API}/payloads/query`, {
json: {
query: {
'dragon.capsule': capsule.id,
@@ -36,7 +36,7 @@ module.exports = async () => {
responseType: 'json',
});

const landLandings = await got.post(`${SPACEX_API}/payloads/query`, {
const landLandings = await got.post(`${API}/payloads/query`, {
json: {
query: {
'dragon.capsule': capsule.id,
@@ -50,7 +50,7 @@ module.exports = async () => {
responseType: 'json',
});

await got.patch(`${SPACEX_API}/capsules/${capsule.id}`, {
await got.patch(`${API}/capsules/${capsule.id}`, {
json: {
reuse_count: capsule.launches.length,
water_landings: waterLandings.totalDocs,
22 changes: 11 additions & 11 deletions jobs/cores.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ const cheerio = require('cheerio');
const { logger } = require('../middleware/logger');

const REDDIT_CORES = 'https://old.reddit.com/r/spacex/wiki/cores';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const API = process.env.SPACEX_API;
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.CORES_HEALTHCHECK;

@@ -13,7 +13,7 @@ const HEALTHCHECK = process.env.CORES_HEALTHCHECK;
*/
module.exports = async () => {
try {
const cores = await got.post(`${SPACEX_API}/cores/query`, {
const cores = await got.post(`${API}/cores/query`, {
json: {
options: {
pagination: false,
@@ -36,7 +36,7 @@ module.exports = async () => {
const activeUpdates = activeCores.map(async (coreSerial, index) => {
const coreId = cores.docs.find((core) => core.serial === coreSerial);
if (coreId && coreId.id) {
await got.patch(`${SPACEX_API}/cores/${coreId.id}`, {
await got.patch(`${API}/cores/${coreId.id}`, {
json: {
last_update: activeStatus[parseInt(index, 10)],
status: 'active',
@@ -60,7 +60,7 @@ module.exports = async () => {
const unknownUpdates = unknownCores.map(async (coreSerial, index) => {
const coreId = cores.docs.find((core) => core.serial === coreSerial);
if (coreId && coreId.id) {
await got.patch(`${SPACEX_API}/cores/${coreId.id}`, {
await got.patch(`${API}/cores/${coreId.id}`, {
json: {
last_update: unknownStatus[parseInt(index, 10)],
status: 'unknown',
@@ -84,7 +84,7 @@ module.exports = async () => {
const inactiveUpdates = inactiveCores.map(async (coreSerial, index) => {
const coreId = cores.docs.find((core) => core.serial === coreSerial);
if (coreId?.id) {
await got.patch(`${SPACEX_API}/cores/${coreId.id}`, {
await got.patch(`${API}/cores/${coreId.id}`, {
json: {
last_update: inactiveStatus[parseInt(index, 10)],
status: 'inactive',
@@ -114,7 +114,7 @@ module.exports = async () => {
} else {
status = 'lost';
}
await got.patch(`${SPACEX_API}/cores/${coreId.id}`, {
await got.patch(`${API}/cores/${coreId.id}`, {
json: {
last_update: lostStatus[parseInt(index, 10)],
status,
@@ -131,7 +131,7 @@ module.exports = async () => {
const reuseUpdates = cores.docs.map(async (core) => {
if (!core?.id) return;
const [rtlsAttempts, rtlsLandings, asdsAttempts, asdsLandings] = await Promise.all([
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
upcoming: false,
@@ -151,7 +151,7 @@ module.exports = async () => {
responseType: 'json',
throwHttpErrors: false,
}),
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
upcoming: false,
@@ -172,7 +172,7 @@ module.exports = async () => {
responseType: 'json',
throwHttpErrors: false,
}),
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
upcoming: false,
@@ -193,7 +193,7 @@ module.exports = async () => {
responseType: 'json',
throwHttpErrors: false,
}),
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
upcoming: false,
@@ -215,7 +215,7 @@ module.exports = async () => {
throwHttpErrors: false,
}),
]);
await got.patch(`${SPACEX_API}/cores/${core.id}`, {
await got.patch(`${API}/cores/${core.id}`, {
json: {
reuse_count: (core.launches.length > 0) ? core.launches.length - 1 : 0,
rtls_attempts: rtlsAttempts.totalDocs,
10 changes: 5 additions & 5 deletions jobs/landpads.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got');
const { logger } = require('../middleware/logger');

const SPACEX_API = 'https://api.spacexdata.com/v4';
const API = process.env.SPACEX_API;
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.LANDPADS_HEALTHCHECK;

@@ -11,7 +11,7 @@ const HEALTHCHECK = process.env.LANDPADS_HEALTHCHECK;
*/
module.exports = async () => {
try {
const landpads = await got.post(`${SPACEX_API}/landpads/query`, {
const landpads = await got.post(`${API}/landpads/query`, {
json: {
options: {
pagination: false,
@@ -23,7 +23,7 @@ module.exports = async () => {

const updates = landpads.docs.map(async (landpad) => {
const [attempts, successes] = await Promise.all([
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
cores: {
@@ -42,7 +42,7 @@ module.exports = async () => {
resolveBodyOnly: true,
responseType: 'json',
}),
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
cores: {
@@ -64,7 +64,7 @@ module.exports = async () => {
}),
]);

await got.patch(`${SPACEX_API}/landpads/${landpad.id}`, {
await got.patch(`${API}/landpads/${landpad.id}`, {
json: {
landing_attempts: attempts.totalDocs,
landing_successes: successes.totalDocs,
32 changes: 16 additions & 16 deletions jobs/launches.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ const _ = require('lodash');
const got = require('got');
const { logger } = require('../middleware/logger');

const SPACEX_API = 'https://api.spacexdata.com/v4';
const API = process.env.SPACEX_API;
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.LAUNCHES_HEALTHCHECK;

@@ -12,7 +12,7 @@ const HEALTHCHECK = process.env.LAUNCHES_HEALTHCHECK;
*/
module.exports = async () => {
try {
const launches = await got.post(`${SPACEX_API}/launches/query`, {
const launches = await got.post(`${API}/launches/query`, {
json: {
query: {
upcoming: false,
@@ -39,7 +39,7 @@ module.exports = async () => {
};

// Update capsule launches
const capsules = await got.post(`${SPACEX_API}/capsules/query`, {
const capsules = await got.post(`${API}/capsules/query`, {
json: {
options: {
pagination: false,
@@ -54,7 +54,7 @@ module.exports = async () => {
.filter((launch) => launch.capsules.includes(capsule.id))
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/capsules/${capsule.id}`, {
await got.patch(`${API}/capsules/${capsule.id}`, {
json: {
launches: launchIds,
},
@@ -67,7 +67,7 @@ module.exports = async () => {
await Promise.all(capsuleLaunches);

// Update core launches
const cores = await got.post(`${SPACEX_API}/cores/query`, {
const cores = await got.post(`${API}/cores/query`, {
json: {
options: {
pagination: false,
@@ -82,7 +82,7 @@ module.exports = async () => {
.filter((launch) => launch.cores.find((c) => c.core === core.id))
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/cores/${core.id}`, {
await got.patch(`${API}/cores/${core.id}`, {
json: {
launches: launchIds,
},
@@ -95,7 +95,7 @@ module.exports = async () => {
await Promise.all(coreLaunches);

// Update crew launches
const crewMembers = await got.post(`${SPACEX_API}/crew/query`, {
const crewMembers = await got.post(`${API}/crew/query`, {
json: {
options: {
pagination: false,
@@ -110,7 +110,7 @@ module.exports = async () => {
.filter((launch) => launch.crew.includes(crew.id))
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/crew/${crew.id}`, {
await got.patch(`${API}/crew/${crew.id}`, {
json: {
launches: launchIds,
},
@@ -123,7 +123,7 @@ module.exports = async () => {
await Promise.all(crewLaunches);

// Update landpad launches
const landpads = await got.post(`${SPACEX_API}/landpads/query`, {
const landpads = await got.post(`${API}/landpads/query`, {
json: {
options: {
pagination: false,
@@ -138,7 +138,7 @@ module.exports = async () => {
.filter((launch) => launch.cores.find((c) => c.landpad === landpad.id))
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/landpads/${landpad.id}`, {
await got.patch(`${API}/landpads/${landpad.id}`, {
json: {
launches: launchIds,
},
@@ -151,7 +151,7 @@ module.exports = async () => {
await Promise.all(landpadLaunches);

// Update launchpad launches
const launchpads = await got.post(`${SPACEX_API}/launchpads/query`, {
const launchpads = await got.post(`${API}/launchpads/query`, {
json: {
options: {
pagination: false,
@@ -166,7 +166,7 @@ module.exports = async () => {
.filter((launch) => launch.launchpad === launchpad.id)
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/launchpads/${launchpad.id}`, {
await got.patch(`${API}/launchpads/${launchpad.id}`, {
json: {
launches: launchIds,
},
@@ -179,7 +179,7 @@ module.exports = async () => {
await Promise.all(launchpadLaunches);

// Update payload launches
const payloads = await got.post(`${SPACEX_API}/payloads/query`, {
const payloads = await got.post(`${API}/payloads/query`, {
json: {
options: {
pagination: false,
@@ -192,7 +192,7 @@ module.exports = async () => {
const payloadLaunches = payloads.docs.map(async (payload) => {
const launchId = _.find(launches.docs, (launch) => launch.payloads.includes(payload.id));
if (launchId?.id) {
await got.patch(`${SPACEX_API}/payloads/${payload.id}`, {
await got.patch(`${API}/payloads/${payload.id}`, {
json: {
launch: launchId.id,
},
@@ -206,7 +206,7 @@ module.exports = async () => {
await Promise.all(payloadLaunches);

// Update ship launches
const ships = await got.post(`${SPACEX_API}/ships/query`, {
const ships = await got.post(`${API}/ships/query`, {
json: {
options: {
pagination: false,
@@ -221,7 +221,7 @@ module.exports = async () => {
.filter((launch) => launch.ships.includes(ship.id))
.map(({ id }) => id);

await got.patch(`${SPACEX_API}/ships/${ship.id}`, {
await got.patch(`${API}/ships/${ship.id}`, {
json: {
launches: launchIds,
},
10 changes: 5 additions & 5 deletions jobs/launchpads.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const got = require('got');
const { logger } = require('../middleware/logger');

const SPACEX_API = 'https://api.spacexdata.com/v4';
const API = process.env.SPACEX_API;
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.LAUNCHPADS_HEALTHCHECK;

@@ -11,7 +11,7 @@ const HEALTHCHECK = process.env.LAUNCHPADS_HEALTHCHECK;
*/
module.exports = async () => {
try {
const launchpads = await got.post(`${SPACEX_API}/launchpads/query`, {
const launchpads = await got.post(`${API}/launchpads/query`, {
json: {
options: {
pagination: false,
@@ -23,7 +23,7 @@ module.exports = async () => {

const updates = launchpads.docs.map(async (launchpad) => {
const [attempts, successes] = await Promise.all([
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
launchpad: launchpad.id,
@@ -36,7 +36,7 @@ module.exports = async () => {
resolveBodyOnly: true,
responseType: 'json',
}),
got.post(`${SPACEX_API}/launches/query`, {
got.post(`${API}/launches/query`, {
json: {
query: {
launchpad: launchpad.id,
@@ -52,7 +52,7 @@ module.exports = async () => {
}),
]);

await got.patch(`${SPACEX_API}/launchpads/${launchpad.id}`, {
await got.patch(`${API}/launchpads/${launchpad.id}`, {
json: {
launch_attempts: attempts.totalDocs,
launch_successes: successes.totalDocs,
Loading

0 comments on commit 10f4f56

Please sign in to comment.