Deployment API typing.

This commit is contained in:
mike12345567 2024-11-29 17:59:08 +00:00
parent 1094b88042
commit fd71afde1d
4 changed files with 49 additions and 15 deletions

View File

@ -1,4 +1,5 @@
import { context, utils } from "@budibase/backend-core"
import { DeploymentStatus } from "@budibase/types"
/**
* This is used to pass around information about the deployment that is occurring
@ -6,7 +7,7 @@ import { context, utils } from "@budibase/backend-core"
export default class Deployment {
_id: string
verification: any
status?: string
status?: DeploymentStatus
err?: any
appUrl?: string
@ -25,7 +26,7 @@ export default class Deployment {
return this.verification
}
setStatus(status: string, err?: any) {
setStatus(status: DeploymentStatus, err?: any) {
this.status = status
if (err) {
this.err = err

View File

@ -10,22 +10,23 @@ import { backups } from "@budibase/pro"
import {
App,
AppBackupTrigger,
DeploymentDoc,
FetchDeploymentResponse,
PublishAppResponse,
UserCtx,
DeploymentStatus,
DeploymentProgressResponse,
} from "@budibase/types"
import sdk from "../../../sdk"
import { builderSocket } from "../../../websockets"
// the max time we can wait for an invalidation to complete before considering it failed
const MAX_PENDING_TIME_MS = 30 * 60000
const DeploymentStatus = {
SUCCESS: "SUCCESS",
PENDING: "PENDING",
FAILURE: "FAILURE",
}
// checks that deployments are in a good state, any pending will be updated
async function checkAllDeployments(deployments: any) {
async function checkAllDeployments(
deployments: any
): Promise<{ updated: boolean; deployments: DeploymentDoc }> {
let updated = false
let deployment: any
for (deployment of Object.values(deployments.history)) {
@ -101,7 +102,9 @@ async function initDeployedApp(prodAppId: any) {
})
}
export async function fetchDeployments(ctx: any) {
export async function fetchDeployments(
ctx: UserCtx<void, FetchDeploymentResponse>
) {
try {
const db = context.getAppDB()
const deploymentDoc = await db.get(DocumentType.DEPLOYMENTS)
@ -109,17 +112,21 @@ export async function fetchDeployments(ctx: any) {
if (updated) {
await db.put(deployments)
}
ctx.body = Object.values(deployments.history).reverse()
ctx.body = deployments.history
? Object.values(deployments.history).reverse()
: []
} catch (err) {
ctx.body = []
}
}
export async function deploymentProgress(ctx: any) {
export async function deploymentProgress(
ctx: UserCtx<void, DeploymentProgressResponse>
) {
try {
const db = context.getAppDB()
const deploymentDoc = await db.get<any>(DocumentType.DEPLOYMENTS)
ctx.body = deploymentDoc[ctx.params.deploymentId]
const deploymentDoc = await db.get<DeploymentDoc>(DocumentType.DEPLOYMENTS)
ctx.body = deploymentDoc.history?.[ctx.params.deploymentId]
} catch (err) {
ctx.throw(
500,

View File

@ -1,3 +1,14 @@
import { DeploymentDoc } from "../../documents"
import { DeploymentDoc, DeploymentStatus } from "../../documents"
export interface PublishAppResponse extends DeploymentDoc {}
export type DeploymentProgressResponse =
| {
_id: string
appId: string
status?: DeploymentStatus
updatedAt: number
}
| undefined
export type FetchDeploymentResponse = DeploymentProgressResponse[]

View File

@ -1,7 +1,22 @@
export enum DeploymentStatus {
SUCCESS = "SUCCESS",
PENDING = "PENDING",
FAILURE = "FAILURE",
}
export interface DeploymentDoc {
_id: string
verification: any
status?: string
status?: DeploymentStatus
history?: Record<
string,
{
_id: string
appId: string
status?: DeploymentStatus
updatedAt: number
}
>
err?: any
appUrl?: string
}