Skip to content

Commit

Permalink
add starlink update job
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Jun 19, 2020
1 parent dcd6fb7 commit 534435a
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 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://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.CAPSULES_HEALTHCHECK;

Expand Down
2 changes: 1 addition & 1 deletion jobs/cores.js
Original file line number Diff line number Diff line change
Expand Up @@ -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://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.CORES_HEALTHCHECK;

Expand Down
2 changes: 1 addition & 1 deletion 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://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.LANDPADS_HEALTHCHECK;

Expand Down
2 changes: 1 addition & 1 deletion jobs/launches.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const _ = require('lodash');
const got = require('got');
const { logger } = require('../middleware/logger');

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

Expand Down
2 changes: 1 addition & 1 deletion 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://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.LAUNCHPADS_HEALTHCHECK;

Expand Down
2 changes: 1 addition & 1 deletion jobs/payloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const got = require('got');
const { CookieJar } = require('tough-cookie');
const { logger } = require('../middleware/logger');

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

Expand Down
2 changes: 1 addition & 1 deletion jobs/roadster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const moment = require('moment-timezone');
const shell = require('shelljs');
const { logger } = require('../middleware/logger');

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

Expand Down
101 changes: 101 additions & 0 deletions jobs/starlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const got = require('got');
const { CookieJar } = require('tough-cookie');
const { logger } = require('../middleware/logger');

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

/**
* Update payload orbit params
* @return {Promise<void>}
*/
module.exports = async () => {
try {
const cookieJar = new CookieJar();

await got.post('https://www.space-track.org/ajaxauth/login', {
form: {
identity: process.env.SPACEX_TRACK_LOGIN,
password: process.env.SPACEX_TRACK_PASSWORD,
},
cookieJar,
});

// eslint-disable-next-line no-secrets/no-secrets
const data = await got('https://www.space-track.org/basicspacedata/query/class/gp/EPOCH/%3Enow-30/orderby/NORAD_CAT_ID%20asc/emptyresult/show', {
resolveBodyOnly: true,
responseType: 'json',
cookieJar,
});

const starlinkSats = data.filter((sat) => /starlink/i.test(sat.OBJECT_NAME));

starlinkSats.forEach((sat) => {
console.log(sat.OBJECT_NAME);
});

const updates = starlinkSats.map(async (sat) => {
await got.patch(`${SPACEX_API}/starlink/${sat.NORAD_CAT_ID}`, {
json: {
CCSDS_OMM_VERS: sat.CCSDS_OMM_VERS,
COMMENT: sat.COMMENT,
CREATION_DATE: sat.CREATION_DATE,
ORIGINATOR: sat.ORIGINATOR,
OBJECT_NAME: sat.OBJECT_NAME,
OBJECT_ID: sat.OBJECT_ID,
CENTER_NAME: sat.CENTER_NAME,
REF_FRAME: sat.REF_FRAME,
TIME_SYSTEM: sat.TIME_SYSTEM,
MEAN_ELEMENT_THEORY: sat.MEAN_ELEMENT_THEORY,
EPOCH: sat.EPOCH,
MEAN_MOTION: sat.MEAN_MOTION,
ECCENTRICITY: sat.ECCENTRICITY,
INCLINATION: sat.INCLINATION,
RA_OF_ASC_NODE: sat.RA_OF_ASC_NODE,
ARG_OF_PERICENTER: sat.ARG_OF_PERICENTER,
MEAN_ANOMALY: sat.MEAN_ANOMALY,
EPHEMERIS_TYPE: sat.EPHEMERIS_TYPE,
CLASSIFICATION_TYPE: sat.CLASSIFICATION_TYPE,
NORAD_CAT_ID: sat.NORAD_CAT_ID,
ELEMENT_SET_NO: sat.ELEMENT_SET_NO,
REV_AT_EPOCH: sat.REV_AT_EPOCH,
BSTAR: sat.BSTAR,
MEAN_MOTION_DOT: sat.MEAN_MOTION_DOT,
MEAN_MOTION_DDOT: sat.MEAN_MOTION_DDOT,
SEMIMAJOR_AXIS: sat.SEMIMAJOR_AXIS,
PERIOD: sat.PERIOD,
APOAPSIS: sat.APOAPSIS,
PERIAPSIS: sat.PERIAPSIS,
OBJECT_TYPE: sat.OBJECT_TYPE,
RCS_SIZE: sat.RCS_SIZE,
COUNTRY_CODE: sat.COUNTRY_CODE,
LAUNCH_DATE: sat.LAUNCH_DATE,
SITE: sat.SITE,
DECAY_DATE: sat.DECAY_DATE,
DECAYED: sat.DECAYED,
FILE: sat.FILE,
GP_ID: sat.GP_ID,
TLE_LINE0: sat.TLE_LINE0,
TLE_LINE1: sat.TLE_LINE1,
TLE_LINE2: sat.TLE_LINE2,
},
headers: {
'spacex-key': KEY,
},
});
});

await Promise.all(updates);

logger.info({
starlinkUpdated: true,
});

if (HEALTHCHECK) {
await got(HEALTHCHECK);
}
} catch (error) {
console.log(error);
}
};
2 changes: 1 addition & 1 deletion jobs/upcoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const moment = require('moment-timezone');
const { logger } = require('../middleware/logger');

const REDDIT_WIKI = 'https://old.reddit.com/r/spacex/wiki/launches/manifest';
const SPACEX_API = 'https://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.UPCOMING_HEALTHCHECK;

Expand Down
2 changes: 1 addition & 1 deletion jobs/webcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fuzz = require('fuzzball');
const { logger } = require('../middleware/logger');

const SPACEX_WEBCAST = 'https://www.spacex.com/webcast';
const SPACEX_API = 'https://stage.spacexdata.com/v4';
const SPACEX_API = 'https://api.spacexdata.com/v4';
const KEY = process.env.SPACEX_KEY;
const HEALTHCHECK = process.env.WEBCAST_HEALTHCHECK;

Expand Down
5 changes: 5 additions & 0 deletions jobs/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const capsules = require('./capsules');
const cores = require('./cores');
const roadster = require('./roadster');
const upcoming = require('./upcoming');
const starlink = require('./starlink');

// Every 10 minutes
// const webcastJob = new CronJob('*/10 * * * *', webcast);
Expand Down Expand Up @@ -36,6 +37,9 @@ const roadsterJob = new CronJob('*/10 * * * *', roadster);
// Every 10 minutes
const upcomingJob = new CronJob('*/10 * * * *', upcoming);

// Every hour on :20
const starlinkJob = new CronJob('55 * * * *', starlink);

// webcastJob.start();
launchesJob.start();
payloadsJob.start();
Expand All @@ -45,3 +49,4 @@ capsulesJob.start();
coresJob.start();
roadsterJob.start();
upcomingJob.start();
starlinkJob.start();

0 comments on commit 534435a

Please sign in to comment.