1
0
Fork 0
mirror of synced 2024-06-14 16:35:02 +12:00
budibase/packages/backend-core/src/events/publishers/backfill.ts
2022-05-30 21:46:08 +01:00

68 lines
1.7 KiB
TypeScript

import { publishEvent } from "../events"
import {
Event,
AppBackfillSucceededEvent,
AppBackfillFailedEvent,
TenantBackfillSucceededEvent,
TenantBackfillFailedEvent,
InstallationBackfillSucceededEvent,
InstallationBackfillFailedEvent,
} from "@budibase/types"
const env = require("../../environment")
const shouldSkip = !env.SELF_HOSTED && !env.isDev()
export async function appSucceeded(properties: AppBackfillSucceededEvent) {
if (shouldSkip) {
return
}
await publishEvent(Event.APP_BACKFILL_SUCCEEDED, properties)
}
export async function appFailed(error: any) {
if (shouldSkip) {
return
}
const properties: AppBackfillFailedEvent = {
error: JSON.stringify(error, Object.getOwnPropertyNames(error)),
}
await publishEvent(Event.APP_BACKFILL_FAILED, properties)
}
export async function tenantSucceeded(
properties: TenantBackfillSucceededEvent
) {
if (shouldSkip) {
return
}
await publishEvent(Event.TENANT_BACKFILL_SUCCEEDED, properties)
}
export async function tenantFailed(error: any) {
if (shouldSkip) {
return
}
const properties: TenantBackfillFailedEvent = {
error: JSON.stringify(error, Object.getOwnPropertyNames(error)),
}
await publishEvent(Event.TENANT_BACKFILL_FAILED, properties)
}
export async function installationSucceeded() {
if (shouldSkip) {
return
}
const properties: InstallationBackfillSucceededEvent = {}
await publishEvent(Event.INSTALLATION_BACKFILL_SUCCEEDED, properties)
}
export async function installationFailed(error: any) {
if (shouldSkip) {
return
}
const properties: InstallationBackfillFailedEvent = {
error: JSON.stringify(error, Object.getOwnPropertyNames(error)),
}
await publishEvent(Event.INSTALLATION_BACKFILL_FAILED, properties)
}