Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispatch board robustness patch #324

Merged
merged 4 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For detailed rules of this file, see [Changelog Rules](#changelog-rules)


### 🐛 Fixed
*
* Resolved crash which would occur if rescue quotes is null. - [#324][]


### ⚙ Tasks
Expand All @@ -54,6 +54,7 @@ For detailed rules of this file, see [Changelog Rules](#changelog-rules)
[#317]: https://github.com/fuelRats/fuelrats.com/pull/317
[#320]: https://github.com/fuelRats/fuelrats.com/pull/320
[#323]: https://github.com/fuelRats/fuelrats.com/pull/323
[#324]: https://github.com/fuelRats/fuelrats.com/pull/324
[2.13.0]: https://github.com/FuelRats/fuelrats.com/compare/v2.12.10...v2.13.0


Expand Down
15 changes: 11 additions & 4 deletions src/hooks/rescueHooks.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { HttpStatus } from '@fuelrats/web-util/http'
import axios from 'axios'
import { useMemo, useState, useEffect } from 'react'

import { getLanguage } from '~/data/LanguageList'
import { getPlatform } from '~/data/PlatformList'
import { formatAsEliteDateTime } from '~/helpers/formatTime'


const pollTimeoutTime = 10000

export const useQuoteString = (rescue) => {
return useMemo(() => {
if (!rescue.attributes.quotes.length) {
if (!rescue?.attributes?.quotes?.length) {
return undefined
}

Expand Down Expand Up @@ -38,11 +42,14 @@ export const useRescueQueueCount = () => {
let timeout = null

const fetchData = async () => {
const { data } = await axios.get('/api/qms/queue')
const { data, status } = await axios.get('/api/qms/queue')

if (status === HttpStatus.OK) {
setCount(data.data.queueLength)
}

setCount(data.data.queueLength)

timeout = setTimeout(fetchData, data.meta.maxAge)
timeout = setTimeout(fetchData, pollTimeoutTime)
}

fetchData()
Expand Down
15 changes: 10 additions & 5 deletions src/pages/api/qms/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function Queue (req, res) {
if (nowTime - cache.lastCheck >= cacheMaxAge) {
cache.lastCheck = nowTime

const result = await axios.get(
const { data, status, statusText } = await axios.get(
`${process.env.QMS_API_URL}/api/v1/queue`,
{
headers: {
Expand All @@ -28,11 +28,16 @@ async function Queue (req, res) {
},
)

const rescueQueue = result.data.filter((rescue) => {
return !rescue.pending && !rescue.in_progress
})
if (status === HttpStatus.OK) {
const rescueQueue = data.filter((rescue) => {
return !rescue.pending && !rescue.in_progress
})

cache.count = rescueQueue.length
cache.count = rescueQueue.length
} else {
res.status(status).end(statusText)
console.error(status, statusText, data)
}
}


Expand Down