From 24d5d2a22cc4c35af8805f6c1dae2e6fcffdcd4d Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Nov 2022 17:15:35 +0000 Subject: [PATCH 1/4] Adding an event for when a backup is triggered. --- .../backend-core/src/events/publishers/backup.ts | 16 +++++++++++++++- packages/types/src/sdk/events/backup.ts | 6 ++++++ packages/types/src/sdk/events/event.ts | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/backend-core/src/events/publishers/backup.ts b/packages/backend-core/src/events/publishers/backup.ts index 0fc81da259..1e41a0a6c0 100644 --- a/packages/backend-core/src/events/publishers/backup.ts +++ b/packages/backend-core/src/events/publishers/backup.ts @@ -1,4 +1,9 @@ -import { AppBackup, AppBackupRestoreEvent, Event } from "@budibase/types" +import { + AppBackup, + AppBackupRestoreEvent, + AppBackupTriggeredEvent, + Event, +} from "@budibase/types" import { publishEvent } from "../events" export async function appBackupRestored(backup: AppBackup) { @@ -10,3 +15,12 @@ export async function appBackupRestored(backup: AppBackup) { await publishEvent(Event.APP_BACKUP_RESTORED, properties) } + +export async function appBackupTriggered(appId: string, name?: string) { + const properties: AppBackupTriggeredEvent = { + appId: appId, + backupName: name, + backupCreatedAt: new Date().toISOString(), + } + await publishEvent(Event.APP_BACKUP_TRIGGERED, properties) +} diff --git a/packages/types/src/sdk/events/backup.ts b/packages/types/src/sdk/events/backup.ts index 8d3e2b1afa..482b895955 100644 --- a/packages/types/src/sdk/events/backup.ts +++ b/packages/types/src/sdk/events/backup.ts @@ -5,3 +5,9 @@ export interface AppBackupRestoreEvent extends BaseEvent { backupName: string backupCreatedAt: string } + +export interface AppBackupTriggeredEvent extends BaseEvent { + appId: string + backupName?: string + backupCreatedAt: string +} diff --git a/packages/types/src/sdk/events/event.ts b/packages/types/src/sdk/events/event.ts index 71caf2bf96..10c5dfc6b0 100644 --- a/packages/types/src/sdk/events/event.ts +++ b/packages/types/src/sdk/events/event.ts @@ -171,6 +171,7 @@ export enum Event { // BACKUP APP_BACKUP_RESTORED = "app:backup:restored", + APP_BACKUP_TRIGGERED = "app:backup:triggered", } // properties added at the final stage of the event pipeline From 3aa5c25da92d15471884ddf3145aaafc669bdc9e Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Thu, 17 Nov 2022 19:38:47 +0000 Subject: [PATCH 2/4] PR comments. --- packages/backend-core/src/events/publishers/backup.ts | 9 +++++++-- packages/types/src/sdk/events/backup.ts | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/backend-core/src/events/publishers/backup.ts b/packages/backend-core/src/events/publishers/backup.ts index 1e41a0a6c0..641ebbb03f 100644 --- a/packages/backend-core/src/events/publishers/backup.ts +++ b/packages/backend-core/src/events/publishers/backup.ts @@ -2,6 +2,7 @@ import { AppBackup, AppBackupRestoreEvent, AppBackupTriggeredEvent, + AppBackupTrigger, Event, } from "@budibase/types" import { publishEvent } from "../events" @@ -16,11 +17,15 @@ export async function appBackupRestored(backup: AppBackup) { await publishEvent(Event.APP_BACKUP_RESTORED, properties) } -export async function appBackupTriggered(appId: string, name?: string) { +export async function appBackupTriggered( + appId: string, + trigger: AppBackupTrigger, + name?: string +) { const properties: AppBackupTriggeredEvent = { appId: appId, backupName: name, - backupCreatedAt: new Date().toISOString(), + trigger, } await publishEvent(Event.APP_BACKUP_TRIGGERED, properties) } diff --git a/packages/types/src/sdk/events/backup.ts b/packages/types/src/sdk/events/backup.ts index 482b895955..7716f86c8a 100644 --- a/packages/types/src/sdk/events/backup.ts +++ b/packages/types/src/sdk/events/backup.ts @@ -1,4 +1,5 @@ import { BaseEvent } from "./event" +import { AppBackupTrigger } from "../../documents/app" export interface AppBackupRestoreEvent extends BaseEvent { appId: string @@ -8,6 +9,6 @@ export interface AppBackupRestoreEvent extends BaseEvent { export interface AppBackupTriggeredEvent extends BaseEvent { appId: string + trigger: AppBackupTrigger backupName?: string - backupCreatedAt: string } From 12a9ed6dcb7883a4aedeb80f7e77b5d90f071dfa Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 17 Nov 2022 23:09:49 +0000 Subject: [PATCH 3/4] Adding type to triggered. --- packages/backend-core/src/events/publishers/backup.ts | 8 ++++---- packages/types/src/sdk/events/backup.ts | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/backend-core/src/events/publishers/backup.ts b/packages/backend-core/src/events/publishers/backup.ts index 641ebbb03f..cb2b058ae8 100644 --- a/packages/backend-core/src/events/publishers/backup.ts +++ b/packages/backend-core/src/events/publishers/backup.ts @@ -3,6 +3,7 @@ import { AppBackupRestoreEvent, AppBackupTriggeredEvent, AppBackupTrigger, + AppBackupType, Event, } from "@budibase/types" import { publishEvent } from "../events" @@ -10,7 +11,6 @@ import { publishEvent } from "../events" export async function appBackupRestored(backup: AppBackup) { const properties: AppBackupRestoreEvent = { appId: backup.appId, - backupName: backup.name!, backupCreatedAt: backup.timestamp, } @@ -19,12 +19,12 @@ export async function appBackupRestored(backup: AppBackup) { export async function appBackupTriggered( appId: string, - trigger: AppBackupTrigger, - name?: string + type: AppBackupType, + trigger: AppBackupTrigger ) { const properties: AppBackupTriggeredEvent = { appId: appId, - backupName: name, + type, trigger, } await publishEvent(Event.APP_BACKUP_TRIGGERED, properties) diff --git a/packages/types/src/sdk/events/backup.ts b/packages/types/src/sdk/events/backup.ts index 7716f86c8a..2f884d5b02 100644 --- a/packages/types/src/sdk/events/backup.ts +++ b/packages/types/src/sdk/events/backup.ts @@ -1,14 +1,13 @@ import { BaseEvent } from "./event" -import { AppBackupTrigger } from "../../documents/app" +import { AppBackupTrigger, AppBackupType } from "../../documents" export interface AppBackupRestoreEvent extends BaseEvent { appId: string - backupName: string backupCreatedAt: string } export interface AppBackupTriggeredEvent extends BaseEvent { appId: string trigger: AppBackupTrigger - backupName?: string + type: AppBackupType } From 3c93101fdb07308aa8ef6f8dc7a20b006f905bb3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 21 Nov 2022 12:12:57 +0000 Subject: [PATCH 4/4] Adding IDs to backup events. --- packages/backend-core/src/events/publishers/backup.ts | 3 +++ packages/types/src/sdk/events/backup.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/backend-core/src/events/publishers/backup.ts b/packages/backend-core/src/events/publishers/backup.ts index cb2b058ae8..4a68364016 100644 --- a/packages/backend-core/src/events/publishers/backup.ts +++ b/packages/backend-core/src/events/publishers/backup.ts @@ -11,6 +11,7 @@ import { publishEvent } from "../events" export async function appBackupRestored(backup: AppBackup) { const properties: AppBackupRestoreEvent = { appId: backup.appId, + restoreId: backup._id!, backupCreatedAt: backup.timestamp, } @@ -19,11 +20,13 @@ export async function appBackupRestored(backup: AppBackup) { export async function appBackupTriggered( appId: string, + backupId: string, type: AppBackupType, trigger: AppBackupTrigger ) { const properties: AppBackupTriggeredEvent = { appId: appId, + backupId, type, trigger, } diff --git a/packages/types/src/sdk/events/backup.ts b/packages/types/src/sdk/events/backup.ts index 2f884d5b02..1dddc109cc 100644 --- a/packages/types/src/sdk/events/backup.ts +++ b/packages/types/src/sdk/events/backup.ts @@ -3,10 +3,12 @@ import { AppBackupTrigger, AppBackupType } from "../../documents" export interface AppBackupRestoreEvent extends BaseEvent { appId: string + restoreId: string backupCreatedAt: string } export interface AppBackupTriggeredEvent extends BaseEvent { + backupId: string appId: string trigger: AppBackupTrigger type: AppBackupType