Skip to content

Commit

Permalink
Many little fixes on the requests calls
Browse files Browse the repository at this point in the history
  • Loading branch information
MaelVB committed Nov 11, 2020
1 parent 32abd2a commit cfd12d5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
15 changes: 11 additions & 4 deletions Services/PayloadDepartment/controllers/sendPayloadInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ const getPayloadInformation = async () => {

};

const sendPayloadInformationToRocket = async () => {

async function sendPayloadInformationToRocketLoop () {
await getPayloadInformation() //Récupère les informations du payload
let telemetry = (await getTelemetry())
while (!isSplit(telemetry)){ //Tant que la rocket n'est pas split, on redemande si elle est split
Expand All @@ -45,6 +44,15 @@ const sendPayloadInformationToRocket = async () => {
return "Payload at place"
}

const sendPayloadInformationToRocket = async () => {
try {
sendPayloadInformationToRocketLoop();
return "Payload service started"
} catch (err) {
console.error(err);
}
}

const payloadInPlace = async() =>{
let atPlace = false
while (!atPlace) {
Expand All @@ -61,7 +69,6 @@ const getTelemetry = async() => {
const response = await got(`${process.env.TELEMETRY_ADDR}/rocketData`)
const telemetry = JSON.parse(response.body)


db.get('telemetries')
.push(telemetry)
.write()
Expand Down Expand Up @@ -96,7 +103,7 @@ const sendToRocket = async (order) => {
};

const sendToMissionCommander = async () => {
const {body} = await got.post(`${process.env.MISSION_COMMANDER_INTERFACE_ADDR}/payloadStatus`, {
const {body} = await got.post(`${process.env.MISSION_ADDR}/payloadStatus`, {
json: {
payloadInPlace: 1
},
Expand Down
7 changes: 2 additions & 5 deletions Services/PayloadDepartment/routes/sendPayloadInformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ const payloadRouter = express.Router();
const payloadController = require('../controllers/sendPayloadInformation');

/**
* Get all modules statics infos
* Start Payload
*/
payloadRouter.route('/').get(async (req, res) => {
try {
const bla = await payloadController.sendPayloadInformationToRocket()
await new Promise(r => setTimeout(r, 1000));
res.json(bla);
res.json(await payloadController.sendPayloadInformationToRocket());
} catch (err) {
console.error(err)
//next (err);
}
});

Expand Down
14 changes: 12 additions & 2 deletions Services/RocketTelemetry/controllers/rocketInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const kafka = new Kafka({
brokers: ['kafka:9092']
})
let isProbing = false

function sleep(s) {
return new Promise(resolve => setTimeout(resolve, s*1000));
}


async function startProb() {
async function startProbLoop() {
isProbing = true
const producer = kafka.producer()
await producer.connect()
Expand All @@ -28,6 +28,16 @@ async function startProb() {
await producer.disconnect()
}

const startProb = async () => {
try {
startProbLoop();
return "Rocket Telemetry started store data"
} catch (err) {
console.error(err);
}
}


function stopProb() {
isProbing = false
console.log("End of probing rocket")
Expand Down
2 changes: 1 addition & 1 deletion Services/Telemetry/controllers/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function startTelemetryKafka() {

const startTelemetry = async () => {
try {
storeRocketData();
startTelemetryKafka();
return "Telemetry started store data"
} catch (err) {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion Services/Telemetry/routes/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const telemetryController = require('../controllers/telemetry');
*/
telemetryRouter.route('/start').get(async (req, res) => {
try {
res.json(await telemetryController.startTelemetryKafka());
res.json(await telemetryController.startTelemetry());
} catch (err) {
next (err);
}
Expand Down
27 changes: 24 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
echo "Start the telemetry service"
curl -s http://localhost:4007/start
isTelemetryStarted=$(curl -s http://localhost:4007/start)
echo $isTelemetryStarted
echo ""
sleep 2

echo "Start the rocket telemetry service"
isRocketTelemetryStarted=$(curl -s http://localhost:4011/start)
echo $isRocketTelemetryStarted
echo ""
sleep 2

echo "Start the web casting service"
isWebCastingStarted=$(curl -s http://localhost:4010/start)
echo $isWebCastingStarted
echo ""
sleep 2

echo "Start the payload service for the mission"
isPayloadServiceStarted=$(curl -s http://localhost:4008/sendPayloadInformation)
echo $isPayloadServiceStarted
echo ""

echo "Try to launch the rocket, weather is the only random variable"
isLaunched=$(curl -s http://localhost:4006/rocketLaunch)
while [ isLaunched == "\"NO GO\"" ]
Expand All @@ -8,9 +29,9 @@ do
isLaunched=$(curl -s http://localhost:4006/rocketLaunch)
done
echo "Rocket is launch"
echo "When the first stage tank is empty the rocket splits in two"
echo "When the first stage tank percentage is at 10%, the rocket splits in two"
telemetry=$(curl -s http://localhost:4007/rocketData)
while [ telemetry != "DESTROYED" ]
while [ telemetry != "\"MISSION SUCCESSFUL !\"" ]
do
echo $telemetry
telemetry=$(curl -s http://localhost:4007/rocketData)
Expand Down

0 comments on commit cfd12d5

Please sign in to comment.