Fixing minor issue with automation quota updates.

This commit is contained in:
mike12345567 2022-05-30 14:06:42 +01:00
parent e87fd9d0a5
commit 06100af834
3 changed files with 14 additions and 3 deletions

View File

@ -5,6 +5,7 @@ const {
getAppId,
updateAppId,
doInAppContext,
doInContext,
} = require("./src/context")
module.exports = {
@ -14,4 +15,5 @@ module.exports = {
getAppId,
updateAppId,
doInAppContext,
doInContext,
}

View File

@ -139,6 +139,16 @@ const setAppTenantId = appId => {
exports.updateTenantId(appTenantId)
}
// gets the tenant ID from the app ID
exports.doInContext = async (appId, task) => {
const tenantId = exports.getTenantIDFromAppID(appId)
return exports.doInTenant(tenantId, async () => {
return exports.doInAppContext(appId, async () => {
return task()
})
})
}
exports.doInAppContext = (appId, task, { forceNew } = {}) => {
if (!appId) {
throw new Error("appId is required")

View File

@ -8,7 +8,7 @@ import { MetadataTypes, WebhookType } from "../constants"
import { getProdAppID, doWithDB } from "@budibase/backend-core/db"
import { cloneDeep } from "lodash/fp"
import { getAppDB, getAppId } from "@budibase/backend-core/context"
import { tenancy } from "@budibase/backend-core"
import { context } from "@budibase/backend-core"
import { quotas } from "@budibase/pro"
const WH_STEP_ID = definitions.WEBHOOK.stepId
@ -22,8 +22,7 @@ export async function processEvent(job: any) {
`${job.data.automation.appId} automation ${automationId} running`
)
// need to actually await these so that an error can be captured properly
const tenantId = tenancy.getTenantIDFromAppID(job.data.event.appId)
return await tenancy.doInTenant(tenantId, async () => {
return await context.doInContext(job.data.event.appId, async () => {
const runFn = () => Runner.run(job)
return quotas.addAutomation(runFn, {
automationId,