Skip to content

Commit

Permalink
Allow retries
Browse files Browse the repository at this point in the history
  • Loading branch information
BenSurgisonGDS committed Feb 15, 2023
1 parent 25e8831 commit b953174
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lib/assets/javascripts/manage-prototype/manage-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ window.GOVUKPrototypeKit.documentReady(() => {
let requestTimeoutId
let timedOut = false
let kitIsRestarting = false
let retries = 0
const timeout = 30 * 1000
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content')

Expand Down Expand Up @@ -65,25 +66,25 @@ window.GOVUKPrototypeKit.documentReady(() => {
postRequest(`/manage-prototype/plugins/${mode}/status`)
.then(response => response.json())
.then(data => {
requestTimeoutId = setTimeout(() => {
if (kitIsRestarting) {
// kit has restarted as the request has returned with data
kitIsRestarting = false
if (data.status === 'processing') {
setTimeout(() => performAction(), 2000)
return
}
if (kitIsRestarting) {
// kit has restarted as the request has returned with data
kitIsRestarting = false
if (data.status === 'processing') {
setTimeout(() => performAction(), 2000)
return
}
if (data.status === 'error') {
clearTimeout(actionTimeoutId)
showErrorStatus()
} else if (data.status === 'completed') {
showCompleteStatus()
} else {
// poll status again if prototype hasn't restarted
}
if (data.status === 'error') {
clearTimeout(actionTimeoutId)
showErrorStatus()
} else if (data.status === 'completed') {
showCompleteStatus()
} else {
// poll status again if prototype hasn't restarted
requestTimeoutId = setTimeout(() => {
pollStatus()
}
}, 1000)
}, 1000)
}
})
.catch(() => {
kitIsRestarting = true
Expand Down Expand Up @@ -128,8 +129,13 @@ window.GOVUKPrototypeKit.documentReady(() => {
break
}
default: {
// Default to error
showErrorStatus()
if (retries > 1) {
// Default to error
showErrorStatus()
} else {
setTimeout(() => performAction(), 2000)
retries++
}
}
}
})
Expand Down

0 comments on commit b953174

Please sign in to comment.