From b355b8bad9a8320172ba3fe9175a279d1ad8093c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 12 Nov 2020 12:58:05 +0000 Subject: [PATCH 1/2] track quota errors in deployment --- .../src/components/deploy/DeploymentHistory.svelte | 11 ++++++++++- packages/server/src/api/controllers/deploy/aws.js | 10 +++++----- packages/server/src/api/controllers/deploy/index.js | 9 +++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index 05a2e40fa6..ed7439eef9 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -7,6 +7,12 @@ import { notifier } from "builderStore/store/notifications" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" + const DeploymentStatus = { + SUCCESS: "SUCCESS", + PENDING: "PENDING", + FAILURE: "FAILURE", + } + const DATE_OPTIONS = { fullDate: { weekday: "long", @@ -56,7 +62,7 @@

Deployment History

- {#if deployments.some(deployment => deployment.status === 'SUCCESS')} + {#if deployments.some(deployment => deployment.status === DeploymentStatus.SUCCESS)} View Your Deployed App → @@ -82,6 +88,9 @@
{deployment.status}
+ {#if deployment.status === DeploymentStatus.FAILURE} + {deployment.err} + {/if}
{/each} diff --git a/packages/server/src/api/controllers/deploy/aws.js b/packages/server/src/api/controllers/deploy/aws.js index 9e62f135a1..d478c4efde 100644 --- a/packages/server/src/api/controllers/deploy/aws.js +++ b/packages/server/src/api/controllers/deploy/aws.js @@ -55,17 +55,17 @@ exports.verifyDeployment = async function({ appId, quota }) { }), }) + const json = await response.json() + if (json.errors) { + throw new Error(json.errors) + } + if (response.status !== 200) { throw new Error( `Error fetching temporary credentials for api key: ${env.BUDIBASE_API_KEY}` ) } - const json = await response.json() - if (json.errors) { - throw new Error(json.errors) - } - // set credentials here, means any time we're verified we're ready to go if (json.credentials) { AWS.config.update({ diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index c3919ebbae..03f91430db 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -21,18 +21,15 @@ const DeploymentStatus = { // checks that deployments are in a good state, any pending will be updated async function checkAllDeployments(deployments) { let updated = false - function update(deployment, status) { - deployment.status = status - updated = true - } - for (let deployment of Object.values(deployments.history)) { // check that no deployments have crashed etc and are now stuck if ( deployment.status === DeploymentStatus.PENDING && Date.now() - deployment.updatedAt > MAX_PENDING_TIME_MS ) { - update(deployment, DeploymentStatus.FAILURE) + deployment.status = status + deployment.err = "Timed out" + updated = true } } return { updated, deployments } From 6906b43667ca06eab8493d802b9f45f85e7143de Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 13 Nov 2020 14:32:47 +0000 Subject: [PATCH 2/2] show quota errors when deployments fail --- .../deploy/DeploymentHistory.svelte | 62 +++++++++++++++++-- .../standard-components/src/RichText.svelte | 32 ++++------ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/packages/builder/src/components/deploy/DeploymentHistory.svelte b/packages/builder/src/components/deploy/DeploymentHistory.svelte index ed7439eef9..8068215969 100644 --- a/packages/builder/src/components/deploy/DeploymentHistory.svelte +++ b/packages/builder/src/components/deploy/DeploymentHistory.svelte @@ -2,7 +2,7 @@ import { onMount, onDestroy } from "svelte" import Spinner from "components/common/Spinner.svelte" import { slide } from "svelte/transition" - import { Heading, Body, Button, Modal } from "@budibase/bbui" + import { Heading, Body, Button, Modal, ModalContent } from "@budibase/bbui" import api from "builderStore/api" import { notifier } from "builderStore/store/notifications" import CreateWebhookDeploymentModal from "./CreateWebhookDeploymentModal.svelte" @@ -31,6 +31,8 @@ export let appId let modal + let errorReasonModal + let errorReason let poll let deployments = [] let deploymentUrl = `https://${appId}.app.budi.live/${appId}` @@ -38,10 +40,35 @@ const formatDate = (date, format) => Intl.DateTimeFormat("en-GB", DATE_OPTIONS[format]).format(date) + // Required to check any updated deployment statuses between polls + function checkIncomingDeploymentStatus(current, incoming) { + for (let incomingDeployment of incoming) { + if (incomingDeployment.status === DeploymentStatus.FAILURE) { + const currentDeployment = current.find( + deployment => deployment._id === incomingDeployment._id + ) + + // We have just been notified of an ongoing deployments failure + if ( + !currentDeployment || + currentDeployment.status === DeploymentStatus.PENDING + ) { + showErrorReasonModal(incomingDeployment.err) + } + } + } + } + async function fetchDeployments() { try { const response = await api.get(`/api/deployments`) - deployments = await response.json() + const json = await response.json() + + if (deployments.length > 0) { + checkIncomingDeploymentStatus(deployments, json) + } + + deployments = json } catch (err) { console.error(err) clearInterval(poll) @@ -49,6 +76,11 @@ } } + function showErrorReasonModal(err) { + errorReason = err + errorReasonModal.show() + } + onMount(() => { fetchDeployments() poll = setInterval(fetchDeployments, POLL_INTERVAL) @@ -86,11 +118,15 @@ {/if}
- {deployment.status} + + {deployment.status} + {#if deployment.status === DeploymentStatus.FAILURE} + showErrorReasonModal(deployment.err)} /> + {/if} +
- {#if deployment.status === DeploymentStatus.FAILURE} - {deployment.err} - {/if} {/each} @@ -100,6 +136,14 @@ + + + {errorReason} + + diff --git a/packages/standard-components/src/RichText.svelte b/packages/standard-components/src/RichText.svelte index a033d3cc1d..af0c190578 100644 --- a/packages/standard-components/src/RichText.svelte +++ b/packages/standard-components/src/RichText.svelte @@ -1,5 +1,5 @@ - - \ No newline at end of file + +