2022-06-16 04:07:17 +12:00
|
|
|
import * as env from "../../environment"
|
2022-07-05 02:44:47 +12:00
|
|
|
import { AutomationResults, Automation, App } from "@budibase/types"
|
2022-07-04 22:43:18 +12:00
|
|
|
import { automations } from "@budibase/pro"
|
2022-07-05 02:44:47 +12:00
|
|
|
import { db as dbUtils } from "@budibase/backend-core"
|
2022-06-18 05:39:06 +12:00
|
|
|
|
2022-06-02 09:39:51 +12:00
|
|
|
export async function storeLog(
|
|
|
|
automation: Automation,
|
|
|
|
results: AutomationResults
|
|
|
|
) {
|
2022-06-18 05:39:06 +12:00
|
|
|
// can disable this if un-needed in self-host, also only do this for prod apps
|
2022-07-05 02:44:47 +12:00
|
|
|
if (env.DISABLE_AUTOMATION_LOGS) {
|
2022-06-16 04:07:17 +12:00
|
|
|
return
|
|
|
|
}
|
2022-07-05 02:44:47 +12:00
|
|
|
await automations.logs.storeLog(automation, results)
|
|
|
|
}
|
2022-06-18 05:39:06 +12:00
|
|
|
|
2022-07-05 02:44:47 +12:00
|
|
|
export async function checkAppMetadata(apps: App[]) {
|
|
|
|
const maxStartDate = await automations.logs.oldestLogDate()
|
|
|
|
for (let metadata of apps) {
|
|
|
|
if (!metadata.automationErrors) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
for (let [key, errors] of Object.entries(metadata.automationErrors)) {
|
|
|
|
const updated = []
|
|
|
|
for (let error of errors) {
|
2022-08-09 03:44:00 +12:00
|
|
|
if (!error) {
|
|
|
|
continue
|
|
|
|
}
|
2022-07-05 02:44:47 +12:00
|
|
|
const startDate = error.split(dbUtils.SEPARATOR)[2]
|
|
|
|
if (startDate > maxStartDate) {
|
|
|
|
updated.push(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
metadata.automationErrors[key] = updated
|
|
|
|
}
|
2022-06-18 05:39:06 +12:00
|
|
|
}
|
2022-07-05 02:44:47 +12:00
|
|
|
return apps
|
2022-06-02 09:39:51 +12:00
|
|
|
}
|