Skip to content

Commit

Permalink
Fix cron jobs issue and update footer information (#420)
Browse files Browse the repository at this point in the history
* Fetching data from Space-Track, fixing some bugs, adding cron tasks for updating database with tool functions

* Orbital chart done, using backend data without refetching from the backend server

* Clean code of orbitalDataGraph, restore strapi files, adding cronTask to the 3rd of each month.

* Adding package*.json files

* ESLint fixed

* Updating strapi env

* Reseting frontend/package.json

* Prettier checked

* Updating for ESlint check

* Adding backend env file

* Revert "Adding backend env file"

This reverts commit 88a46fb.

* Try fixing cron job, error caused by Strapi reloading after updating db

* Fix cron jobs issue and update Footer info
  • Loading branch information
Graulitard committed Aug 12, 2024
1 parent fe064c8 commit 9d17fd2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 42 deletions.
38 changes: 24 additions & 14 deletions backend/config/functions/cronTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,33 @@ module.exports = {
updateAllSatellitesData: {
task: async ({ strapi }) => {
try {
// Fetching all satellites
const satellites = await strapi.entityService.findMany('api::satellite.satellite');

// Waiting for all promises to be resolved
// Fetch all satellites
const satellites = await strapi.entityService.findMany('api::satellite.satellite', {
fields: ['id', 'catalogNumberNORAD'],
filters: {
catalogNumberNORAD: { $ne: null },
}
});
await Promise.all(
satellites.map(async satellite => {
try {
setTimeout(async () => {
await fetchOrbitalData(strapi, satellite.id);
}, 10000);
} catch (error) {
console.error(error);
}
})
);
satellites.map(async (satellite) => {
const fetchedData = await fetchOrbitalData(satellite.catalogNumberNORAD);
return { id: satellite.id, historicalOrbitalData: fetchedData };
})).then(async (historicalOrbitalData) => {
await strapi.db.transaction(async (trx) => {
// Fetch data for each satellite
historicalOrbitalData.map(async (satellite) => {
// Update the database with the new data
const updatedSat = await strapi.entityService.update('api::satellite.satellite', satellite.id, {
data: {
historicalOrbitalData: satellite.historicalOrbitalData,
},
}, { trx });
})
});
})
} catch (error) {
console.error(error);
return;
}
},
options: {
Expand Down
23 changes: 5 additions & 18 deletions backend/config/functions/satelliteUtils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// backend/utils/satelliteUtils.js
const axios = require('axios');

async function fetchOrbitalData(strapi, contextId) {
async function fetchOrbitalData(noradId) {
try {
// Fetching the satellite
const satellite = await strapi.entityService.findOne('api::satellite.satellite', contextId);
const noradId = satellite.catalogNumberNORAD;

// Authentication to Space-Track
const authResponse = await axios.post('https://www.space-track.org/ajaxauth/login', {
identity: 'floridg@stud.ntnu.no',
Expand All @@ -15,7 +11,9 @@ async function fetchOrbitalData(strapi, contextId) {

if (authResponse.status === 200) {
// Fetching data from Space-Track
const satelliteResponse = await axios.get(`https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/${noradId}/orderby/TLE_LINE1%20ASC/EPOCH/1950-07-02--2024-07-02/format/json`, {

const today = new Date();
const satelliteResponse = await axios.get(`https://www.space-track.org/basicspacedata/query/class/gp_history/NORAD_CAT_ID/${noradId}/orderby/TLE_LINE1%20ASC/orderby/TLE_LINE1%20ASC/format/json`, {
headers: {
Cookie: authResponse.headers['set-cookie']
}
Expand All @@ -30,19 +28,8 @@ async function fetchOrbitalData(strapi, contextId) {
eccentricity: data.ECCENTRICITY,
semiMajorAxis: data.SEMIMAJOR_AXIS
}));

// Updating the satellite with the new data
const updatedSatellite = await strapi.entityService.update('api::satellite.satellite', contextId, {
data: {
historicalOrbitalData: historicalOrbitalData,
},
});
return updatedSatellite;
} else {
throw new Error('Error while fetching data from Space-Track');
return historicalOrbitalData;
}
} else {
throw new Error('Authentication failed');
}
} catch (error) {
console.error('Error while fetching data to Space-Track: ', error);
Expand Down
14 changes: 4 additions & 10 deletions frontend/src/components/layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@ export default function Footer() {
<div className="flex flex-col gap-2 text-center">
<div className="flex flex-wrap justify-center gap-x-4">
<a
href="https://www.x.com/NTNU"
className="hover:underline"
>
Twitter
</a>
<a
href="https://www.facebook.com/ntnu.no"
href="https://www.facebook.com/NTNUSmallSat"
className="hover:underline"
>
Facebook
</a>
<a
href="https://www.instagram.com/ntnu"
href="https://www.instagram.com/ntnusmallsat/"
className="hover:underline"
>
Instagram
</a>
<a
href="https://www.youtube.com/user/ntnuinfo"
href="https://www.linkedin.com/company/20559539/"
className="hover:underline"
>
Youtube
LinkedIn
</a>
</div>
<div className="flex flex-row justify-center">
Expand Down

0 comments on commit 9d17fd2

Please sign in to comment.