Fixing minor issue with automation quota updates.
This commit is contained in:
parent
e87fd9d0a5
commit
06100af834
|
@ -5,6 +5,7 @@ const {
|
||||||
getAppId,
|
getAppId,
|
||||||
updateAppId,
|
updateAppId,
|
||||||
doInAppContext,
|
doInAppContext,
|
||||||
|
doInContext,
|
||||||
} = require("./src/context")
|
} = require("./src/context")
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -14,4 +15,5 @@ module.exports = {
|
||||||
getAppId,
|
getAppId,
|
||||||
updateAppId,
|
updateAppId,
|
||||||
doInAppContext,
|
doInAppContext,
|
||||||
|
doInContext,
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,16 @@ const setAppTenantId = appId => {
|
||||||
exports.updateTenantId(appTenantId)
|
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 } = {}) => {
|
exports.doInAppContext = (appId, task, { forceNew } = {}) => {
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
throw new Error("appId is required")
|
throw new Error("appId is required")
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { MetadataTypes, WebhookType } from "../constants"
|
||||||
import { getProdAppID, doWithDB } from "@budibase/backend-core/db"
|
import { getProdAppID, doWithDB } from "@budibase/backend-core/db"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { getAppDB, getAppId } from "@budibase/backend-core/context"
|
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"
|
import { quotas } from "@budibase/pro"
|
||||||
|
|
||||||
const WH_STEP_ID = definitions.WEBHOOK.stepId
|
const WH_STEP_ID = definitions.WEBHOOK.stepId
|
||||||
|
@ -22,8 +22,7 @@ export async function processEvent(job: any) {
|
||||||
`${job.data.automation.appId} automation ${automationId} running`
|
`${job.data.automation.appId} automation ${automationId} running`
|
||||||
)
|
)
|
||||||
// need to actually await these so that an error can be captured properly
|
// need to actually await these so that an error can be captured properly
|
||||||
const tenantId = tenancy.getTenantIDFromAppID(job.data.event.appId)
|
return await context.doInContext(job.data.event.appId, async () => {
|
||||||
return await tenancy.doInTenant(tenantId, async () => {
|
|
||||||
const runFn = () => Runner.run(job)
|
const runFn = () => Runner.run(job)
|
||||||
return quotas.addAutomation(runFn, {
|
return quotas.addAutomation(runFn, {
|
||||||
automationId,
|
automationId,
|
||||||
|
|
Loading…
Reference in New Issue