Skip to content
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
7 changes: 6 additions & 1 deletion frontend/src/api/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ const generateSnapshotDescription = async (deviceId, target) => {
})
}

const getDeviceEditorProxy = async (editorUrl) => {
return client.get(editorUrl)
}

export default {
create,
getDevice,
Expand All @@ -266,5 +270,6 @@ export default {
suspendDevice,
restartDevice,
startDevice,
generateSnapshotDescription
generateSnapshotDescription,
getDeviceEditorProxy
}
21 changes: 18 additions & 3 deletions frontend/src/composables/DeviceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,15 @@ export function useDeviceHelper () {
if (shouldStartPolling) { startPolling() }
}

async function fetchDevice (deviceId = null) {
async function fetchDevice (deviceId = null, shouldSetDevice = true) {
try {
device.value = await deviceApi.getDevice(deviceId || device.value?.id)
const response = await deviceApi.getDevice(deviceId || device.value?.id)

if (shouldSetDevice) {
device.value = response
}

return response
} catch (err) {
if (err.status === 403) {
stopPolling()
Expand Down Expand Up @@ -149,6 +155,14 @@ export function useDeviceHelper () {
})
}

async function getDeviceEditorProxy (device) {
if (device.editor.url) {
return deviceApi.getDeviceEditorProxy(device.editor.url)
}

return Promise.reject(Error('editor url unavailable'))
}

return {
agentSupportsDeviceAccess,
agentSupportsActions,
Expand All @@ -162,6 +176,7 @@ export function useDeviceHelper () {
resumePolling,
restartDevice,
fetchDevice,
showDeleteDialog
showDeleteDialog,
getDeviceEditorProxy
}
}
33 changes: 30 additions & 3 deletions frontend/src/pages/device/Editor/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ export default {
startPolling,
stopPolling,
resumePolling,
pausePolling
pausePolling,
getDeviceEditorProxy
} = useDeviceHelper()

return {
Expand Down Expand Up @@ -157,7 +158,8 @@ export default {
stopPolling,
resumePolling,
pausePolling,
showDeleteDeviceDialog
showDeleteDeviceDialog,
getDeviceEditorProxy
}
},
computed: {
Expand Down Expand Up @@ -312,7 +314,32 @@ export default {
methods: {
...mapActions('context', { setContextDevice: 'setDevice' }),
loadDevice: async function () {
await this.fetchDevice(this.$route.params.id)
let tries = 0
let device = await this.fetchDevice(this.$route.params.id, false)

// When running multiple replicas of the forge app, the affinity token may be missing if the request is routed to a
// backend endpoint that didn't initiate the tunnel. If we receive a 502 from the device editor proxy,
// we retry the editor API call until the correct affinity token is acquired (200/302).
while (tries <= 5) {
Comment thread
cstns marked this conversation as resolved.
try {
await this.getDeviceEditorProxy(device)
break
} catch (e) {
if (e?.response?.status === 502) {
tries += 1

// 1s interval timeout between tries
await new Promise(resolve => setTimeout(resolve, 1000))

device = await this.fetchDevice(this.$route.params.id, false)
continue
}

break
}
}

this.device = device
await this.$store.dispatch('account/setTeam', this.device.team.slug)
},
showConfirmDeleteDialog () {
Expand Down
Loading