@budibase/server 2.0.33 → 2.0.34-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/mongodb.ts +1 -1
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.dfa4073c.css → index.b15ffe95.css} +2 -2
- package/builder/assets/{index.ce49a649.js → index.d09d1931.js} +340 -332
- package/builder/index.html +2 -2
- package/coverage/clover.xml +634 -689
- package/coverage/coverage-final.json +34 -36
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +2 -2
- package/coverage/lcov-report/api/controllers/index.html +17 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +12 -12
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +7 -7
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +5 -20
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +17 -92
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +9 -9
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +26 -26
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +10 -16
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +3 -3
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +37 -316
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +2 -2
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +77 -77
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +11 -11
- package/coverage/lcov-report/middleware/currentapp.js.html +34 -34
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +11 -8
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +15 -15
- package/coverage/lcov-report/utilities/index.js.html +7 -7
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +54 -39
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +1141 -1246
- package/dist/api/controllers/application.js +4 -7
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +7 -2
- package/dist/api/controllers/row/index.js +30 -10
- package/dist/api/controllers/static/index.js +2 -2
- package/dist/api/controllers/static/templates/preview.hbs +10 -0
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +10 -3
- package/dist/api/controllers/table/utils.js +7 -49
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/app.js +14 -0
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +5 -33
- package/dist/automations/index.js +4 -4
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/triggers.js +4 -4
- package/dist/automations/utils.js +18 -12
- package/dist/constants/index.js +4 -5
- package/dist/db/utils.js +10 -75
- package/dist/index.js +1 -0
- package/dist/integrations/arangodb.js +2 -0
- package/dist/integrations/base/sqlTable.js +1 -0
- package/dist/integrations/mongodb.js +300 -11
- package/dist/integrations/rest.js +38 -5
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
- package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
- package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
- package/dist/migrations/index.js +9 -38
- package/dist/package.json +14 -14
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +162 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +15 -0
- package/dist/tests/utilities/TestConfiguration.js +4 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +1 -0
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/rowProcessor/index.js +5 -0
- package/dist/utilities/usageQuota/rows.js +6 -4
- package/package.json +15 -15
- package/specs/openapi.json +3 -0
- package/specs/openapi.yaml +3 -0
- package/src/api/controllers/application.ts +5 -12
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -8
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +8 -2
- package/src/api/controllers/row/index.ts +36 -13
- package/src/api/controllers/static/index.ts +2 -2
- package/src/api/controllers/static/templates/preview.hbs +10 -0
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +8 -9
- package/src/api/controllers/table/utils.ts +4 -53
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/api/routes/tests/row.spec.js +22 -27
- package/src/app.ts +15 -0
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +8 -33
- package/src/automations/index.js +4 -4
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +1 -6
- package/src/automations/triggers.js +4 -4
- package/src/automations/utils.ts +18 -12
- package/src/constants/index.js +4 -6
- package/src/db/utils.js +17 -110
- package/src/definitions/automations.ts +0 -12
- package/src/definitions/datasource.ts +1 -0
- package/src/index.ts +1 -0
- package/src/integrations/arangodb.ts +2 -0
- package/src/integrations/base/sqlTable.ts +1 -0
- package/src/integrations/mongodb.ts +290 -27
- package/src/integrations/rest.ts +17 -5
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +38 -22
- package/src/migrations/functions/backfill/app/tables.ts +7 -13
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
- package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +5 -2
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
- package/src/migrations/index.ts +20 -45
- package/src/migrations/tests/index.spec.ts +0 -1
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +169 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +78 -0
- package/src/sdk/app/tables/index.ts +61 -0
- package/src/sdk/index.ts +13 -0
- package/src/tests/utilities/TestConfiguration.js +5 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/csvParser.js +1 -0
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/rowProcessor/index.js +5 -0
- package/src/utilities/usageQuota/rows.js +7 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
- package/src/migrations/functions/pluginCount.ts +0 -12
|
@@ -1,37 +1,17 @@
|
|
|
1
1
|
const { createBullBoard } = require("@bull-board/api")
|
|
2
2
|
const { BullAdapter } = require("@bull-board/api/bullAdapter")
|
|
3
3
|
const { KoaAdapter } = require("@bull-board/koa")
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
? require("../utilities/queue/inMemoryQueue")
|
|
7
|
-
: require("bull")
|
|
8
|
-
const { JobQueues } = require("../constants")
|
|
9
|
-
const { utils } = require("@budibase/backend-core/redis")
|
|
10
|
-
const { opts, redisProtocolUrl } = utils.getRedisOptions()
|
|
11
|
-
const listeners = require("./listeners")
|
|
4
|
+
const { queue } = require("@budibase/backend-core")
|
|
5
|
+
const automation = require("../threads/automation")
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
let automationQueue = new Queue(JobQueues.AUTOMATIONS, queueConfig)
|
|
18
|
-
listeners.addListeners(automationQueue)
|
|
19
|
-
|
|
20
|
-
async function cleanup() {
|
|
21
|
-
await automationQueue.clean(CLEANUP_PERIOD_MS, "completed")
|
|
22
|
-
}
|
|
7
|
+
let automationQueue = queue.createQueue(
|
|
8
|
+
queue.JobQueue.AUTOMATION,
|
|
9
|
+
automation.removeStalled
|
|
10
|
+
)
|
|
23
11
|
|
|
24
12
|
const PATH_PREFIX = "/bulladmin"
|
|
25
13
|
|
|
26
14
|
exports.init = () => {
|
|
27
|
-
// cleanup the events every 5 minutes
|
|
28
|
-
if (!cleanupInternal) {
|
|
29
|
-
cleanupInternal = setInterval(cleanup, CLEANUP_PERIOD_MS)
|
|
30
|
-
// fire off an initial cleanup
|
|
31
|
-
cleanup().catch(err => {
|
|
32
|
-
console.error(`Unable to cleanup automation queue initially - ${err}`)
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
15
|
// Set up queues for bull board admin
|
|
36
16
|
const queues = [automationQueue]
|
|
37
17
|
const adapters = []
|
|
@@ -48,12 +28,7 @@ exports.init = () => {
|
|
|
48
28
|
}
|
|
49
29
|
|
|
50
30
|
exports.shutdown = async () => {
|
|
51
|
-
|
|
52
|
-
clearInterval(cleanupInternal)
|
|
53
|
-
await automationQueue.close()
|
|
54
|
-
automationQueue = null
|
|
55
|
-
}
|
|
56
|
-
console.log("Bull shutdown")
|
|
31
|
+
await queue.shutdown()
|
|
57
32
|
}
|
|
58
33
|
|
|
59
|
-
exports.
|
|
34
|
+
exports.automationQueue = automationQueue
|
package/src/automations/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { processEvent } = require("./utils")
|
|
2
|
-
const {
|
|
2
|
+
const { automationQueue, shutdown } = require("./bullboard")
|
|
3
3
|
const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers")
|
|
4
4
|
const { ACTION_DEFINITIONS } = require("./actions")
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ const { ACTION_DEFINITIONS } = require("./actions")
|
|
|
8
8
|
*/
|
|
9
9
|
exports.init = async function () {
|
|
10
10
|
// this promise will not complete
|
|
11
|
-
const promise =
|
|
11
|
+
const promise = automationQueue.process(async job => {
|
|
12
12
|
await processEvent(job)
|
|
13
13
|
})
|
|
14
14
|
// on init we need to trigger any reboot automations
|
|
@@ -17,13 +17,13 @@ exports.init = async function () {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
exports.getQueues = () => {
|
|
20
|
-
return [
|
|
20
|
+
return [automationQueue]
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
exports.shutdown = () => {
|
|
24
24
|
return shutdown()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
exports.
|
|
27
|
+
exports.automationQueue = automationQueue
|
|
28
28
|
exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
|
|
29
29
|
exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS
|
|
@@ -66,9 +66,9 @@ exports.run = async function ({ inputs, appId, emitter }) {
|
|
|
66
66
|
}
|
|
67
67
|
const tableId = inputs.row.tableId
|
|
68
68
|
|
|
69
|
-
// clear any
|
|
69
|
+
// clear any undefined, null or empty string properties so that they aren't updated
|
|
70
70
|
for (let propKey of Object.keys(inputs.row)) {
|
|
71
|
-
if (
|
|
71
|
+
if (inputs.row[propKey] == null || inputs.row[propKey] === "") {
|
|
72
72
|
delete inputs.row[propKey]
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -29,16 +29,11 @@ describe("Run through some parts of the automations system", () => {
|
|
|
29
29
|
afterAll(setup.afterAll)
|
|
30
30
|
|
|
31
31
|
it("should be able to init in builder", async () => {
|
|
32
|
-
await triggers.externalTrigger(basicAutomation(), { a: 1 })
|
|
32
|
+
await triggers.externalTrigger(basicAutomation(), { a: 1, appId: "app_123" })
|
|
33
33
|
await wait(100)
|
|
34
34
|
expect(thread.execute).toHaveBeenCalled()
|
|
35
35
|
})
|
|
36
36
|
|
|
37
|
-
it("should be able to init in prod", async () => {
|
|
38
|
-
await triggers.externalTrigger(basicAutomation(), { a: 1 })
|
|
39
|
-
await wait(100)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
37
|
it("should check coercion", async () => {
|
|
43
38
|
const table = await config.createTable()
|
|
44
39
|
const automation = basicAutomation()
|
|
@@ -4,7 +4,7 @@ const { coerce } = require("../utilities/rowProcessor")
|
|
|
4
4
|
const { definitions } = require("./triggerInfo")
|
|
5
5
|
const { isDevAppID } = require("../db/utils")
|
|
6
6
|
// need this to call directly, so we can get a response
|
|
7
|
-
const {
|
|
7
|
+
const { automationQueue } = require("./bullboard")
|
|
8
8
|
const { checkTestFlag } = require("../utilities/redis")
|
|
9
9
|
const utils = require("./utils")
|
|
10
10
|
const env = require("../environment")
|
|
@@ -56,7 +56,7 @@ async function queueRelevantRowAutomations(event, eventType) {
|
|
|
56
56
|
automationTrigger.inputs &&
|
|
57
57
|
automationTrigger.inputs.tableId === event.row.tableId
|
|
58
58
|
) {
|
|
59
|
-
await
|
|
59
|
+
await automationQueue.add({ automation, event }, JOB_OPTS)
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
})
|
|
@@ -110,7 +110,7 @@ exports.externalTrigger = async function (
|
|
|
110
110
|
if (getResponses) {
|
|
111
111
|
return utils.processEvent({ data })
|
|
112
112
|
} else {
|
|
113
|
-
return
|
|
113
|
+
return automationQueue.add(data, JOB_OPTS)
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
|
|
@@ -136,7 +136,7 @@ exports.rebootTrigger = async () => {
|
|
|
136
136
|
timestamp: Date.now(),
|
|
137
137
|
},
|
|
138
138
|
}
|
|
139
|
-
rebootEvents.push(
|
|
139
|
+
rebootEvents.push(automationQueue.add(job, JOB_OPTS))
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
await Promise.all(rebootEvents)
|
package/src/automations/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Thread, ThreadType } from "../threads"
|
|
2
2
|
import { definitions } from "./triggerInfo"
|
|
3
3
|
import * as webhooks from "../api/controllers/webhook"
|
|
4
|
-
import {
|
|
4
|
+
import { automationQueue } from "./bullboard"
|
|
5
5
|
import newid from "../db/newid"
|
|
6
6
|
import { updateEntityMetadata } from "../utilities"
|
|
7
7
|
import { MetadataTypes, WebhookType } from "../constants"
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
getAppId,
|
|
14
14
|
getProdAppDB,
|
|
15
15
|
} from "@budibase/backend-core/context"
|
|
16
|
-
import {
|
|
16
|
+
import { context } from "@budibase/backend-core"
|
|
17
17
|
import { quotas } from "@budibase/pro"
|
|
18
18
|
import { Automation } from "@budibase/types"
|
|
19
19
|
|
|
@@ -28,12 +28,14 @@ const jobMessage = (job: any, message: string) => {
|
|
|
28
28
|
|
|
29
29
|
export async function processEvent(job: any) {
|
|
30
30
|
try {
|
|
31
|
+
const automationId = job.data.automation._id
|
|
31
32
|
console.log(jobMessage(job, "running"))
|
|
32
33
|
// need to actually await these so that an error can be captured properly
|
|
33
|
-
|
|
34
|
-
return await tenancy.doInTenant(tenantId, async () => {
|
|
34
|
+
return await context.doInContext(job.data.event.appId, async () => {
|
|
35
35
|
const runFn = () => Runner.run(job)
|
|
36
|
-
return quotas.addAutomation(runFn
|
|
36
|
+
return quotas.addAutomation(runFn, {
|
|
37
|
+
automationId,
|
|
38
|
+
})
|
|
37
39
|
})
|
|
38
40
|
} catch (err) {
|
|
39
41
|
const errJson = JSON.stringify(err)
|
|
@@ -77,21 +79,25 @@ export function removeDeprecated(definitions: any) {
|
|
|
77
79
|
// end the repetition and the job itself
|
|
78
80
|
export async function disableAllCrons(appId: any) {
|
|
79
81
|
const promises = []
|
|
80
|
-
const jobs = await
|
|
82
|
+
const jobs = await automationQueue.getRepeatableJobs()
|
|
81
83
|
for (let job of jobs) {
|
|
82
84
|
if (job.key.includes(`${appId}_cron`)) {
|
|
83
|
-
promises.push(
|
|
85
|
+
promises.push(automationQueue.removeRepeatableByKey(job.key))
|
|
84
86
|
if (job.id) {
|
|
85
|
-
promises.push(
|
|
87
|
+
promises.push(automationQueue.removeJobs(job.id))
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
return Promise.all(promises)
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
export async function
|
|
93
|
-
await
|
|
94
|
-
|
|
94
|
+
export async function disableCronById(jobId: number | string) {
|
|
95
|
+
const repeatJobs = await automationQueue.getRepeatableJobs()
|
|
96
|
+
for (let repeatJob of repeatJobs) {
|
|
97
|
+
if (repeatJob.id === jobId) {
|
|
98
|
+
await automationQueue.removeRepeatableByKey(repeatJob.key)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
95
101
|
console.log(`jobId=${jobId} disabled`)
|
|
96
102
|
}
|
|
97
103
|
|
|
@@ -139,7 +145,7 @@ export async function enableCronTrigger(appId: any, automation: Automation) {
|
|
|
139
145
|
) {
|
|
140
146
|
// make a job id rather than letting Bull decide, makes it easier to handle on way out
|
|
141
147
|
const jobId = `${appId}_cron_${newid()}`
|
|
142
|
-
const job: any = await
|
|
148
|
+
const job: any = await automationQueue.add(
|
|
143
149
|
{
|
|
144
150
|
automation,
|
|
145
151
|
event: { appId, timestamp: Date.now() },
|
package/src/constants/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
|
2
2
|
const { UserStatus } = require("@budibase/backend-core/constants")
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
exports.JobQueues = {
|
|
6
|
-
AUTOMATIONS: "automationQueue",
|
|
7
|
-
}
|
|
3
|
+
const { objectStore } = require("@budibase/backend-core")
|
|
8
4
|
|
|
9
5
|
const FilterTypes = {
|
|
10
6
|
STRING: "string",
|
|
@@ -31,6 +27,7 @@ exports.NoEmptyFilterStrings = [
|
|
|
31
27
|
|
|
32
28
|
exports.FieldTypes = {
|
|
33
29
|
STRING: "string",
|
|
30
|
+
BARCODEQR: "barcodeqr",
|
|
34
31
|
LONGFORM: "longform",
|
|
35
32
|
OPTIONS: "options",
|
|
36
33
|
NUMBER: "number",
|
|
@@ -51,6 +48,7 @@ exports.CanSwitchTypes = [
|
|
|
51
48
|
exports.FieldTypes.STRING,
|
|
52
49
|
exports.FieldTypes.OPTIONS,
|
|
53
50
|
exports.FieldTypes.LONGFORM,
|
|
51
|
+
exports.FieldTypes.BARCODEQR,
|
|
54
52
|
],
|
|
55
53
|
[exports.FieldTypes.BOOLEAN, exports.FieldTypes.NUMBER],
|
|
56
54
|
]
|
|
@@ -209,6 +207,6 @@ exports.AutomationErrors = {
|
|
|
209
207
|
}
|
|
210
208
|
|
|
211
209
|
// pass through the list from the auth/core lib
|
|
212
|
-
exports.ObjectStoreBuckets = ObjectStoreBuckets
|
|
210
|
+
exports.ObjectStoreBuckets = objectStore.ObjectStoreBuckets
|
|
213
211
|
|
|
214
212
|
exports.MAX_AUTOMATION_RECURRING_ERRORS = 5
|
package/src/db/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const newid = require("./newid")
|
|
2
2
|
const {
|
|
3
|
-
DocumentType:
|
|
3
|
+
DocumentType: CoreDocType,
|
|
4
|
+
InternalTable,
|
|
4
5
|
getRoleParams,
|
|
5
6
|
generateRoleID,
|
|
6
7
|
APP_DEV_PREFIX,
|
|
@@ -13,6 +14,12 @@ const {
|
|
|
13
14
|
generateAppID,
|
|
14
15
|
getQueryIndex,
|
|
15
16
|
ViewName,
|
|
17
|
+
getDocParams,
|
|
18
|
+
getRowParams,
|
|
19
|
+
generateRowID,
|
|
20
|
+
getUserMetadataParams,
|
|
21
|
+
generateUserMetadataID,
|
|
22
|
+
getGlobalIDFromUserMetadataID,
|
|
16
23
|
} = require("@budibase/backend-core/db")
|
|
17
24
|
|
|
18
25
|
const UNICODE_MAX = "\ufff0"
|
|
@@ -23,30 +30,7 @@ const AppStatus = {
|
|
|
23
30
|
DEPLOYED: "published",
|
|
24
31
|
}
|
|
25
32
|
|
|
26
|
-
const DocumentType =
|
|
27
|
-
...CoreDocTypes,
|
|
28
|
-
TABLE: "ta",
|
|
29
|
-
ROW: "ro",
|
|
30
|
-
USER: "us",
|
|
31
|
-
AUTOMATION: "au",
|
|
32
|
-
LINK: "li",
|
|
33
|
-
WEBHOOK: "wh",
|
|
34
|
-
INSTANCE: "inst",
|
|
35
|
-
LAYOUT: "layout",
|
|
36
|
-
SCREEN: "screen",
|
|
37
|
-
DATASOURCE: "datasource",
|
|
38
|
-
DATASOURCE_PLUS: "datasource_plus",
|
|
39
|
-
QUERY: "query",
|
|
40
|
-
DEPLOYMENTS: "deployments",
|
|
41
|
-
METADATA: "metadata",
|
|
42
|
-
MEM_VIEW: "view",
|
|
43
|
-
USER_FLAG: "flag",
|
|
44
|
-
AUTOMATION_METADATA: "meta_au",
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const InternalTables = {
|
|
48
|
-
USER_METADATA: "ta_users",
|
|
49
|
-
}
|
|
33
|
+
const DocumentType = CoreDocType
|
|
50
34
|
|
|
51
35
|
const SearchIndexes = {
|
|
52
36
|
ROWS: "rows",
|
|
@@ -66,11 +50,11 @@ exports.APP_PREFIX = APP_PREFIX
|
|
|
66
50
|
exports.APP_DEV_PREFIX = APP_DEV_PREFIX
|
|
67
51
|
exports.isDevAppID = isDevAppID
|
|
68
52
|
exports.isProdAppID = isProdAppID
|
|
69
|
-
exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${
|
|
70
|
-
exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${
|
|
53
|
+
exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
|
|
54
|
+
exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
|
|
71
55
|
exports.TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
|
|
72
56
|
exports.ViewName = ViewName
|
|
73
|
-
exports.InternalTables =
|
|
57
|
+
exports.InternalTables = InternalTable
|
|
74
58
|
exports.DocumentType = DocumentType
|
|
75
59
|
exports.SEPARATOR = SEPARATOR
|
|
76
60
|
exports.UNICODE_MAX = UNICODE_MAX
|
|
@@ -79,36 +63,15 @@ exports.AppStatus = AppStatus
|
|
|
79
63
|
exports.BudibaseInternalDB = BudibaseInternalDB
|
|
80
64
|
exports.generateAppID = generateAppID
|
|
81
65
|
exports.generateDevAppID = getDevelopmentAppID
|
|
82
|
-
|
|
83
66
|
exports.generateRoleID = generateRoleID
|
|
84
67
|
exports.getRoleParams = getRoleParams
|
|
85
|
-
|
|
86
68
|
exports.getQueryIndex = getQueryIndex
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
|
90
|
-
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
|
91
|
-
* More complex cases such as link docs and rows which have multiple levels of IDs that their
|
|
92
|
-
* ID consists of need their own functions to build the allDocs parameters.
|
|
93
|
-
* @param {string} docType The type of document which input params are being built for, e.g. user,
|
|
94
|
-
* link, app, table and so on.
|
|
95
|
-
* @param {string|null} docId The ID of the document minus its type - this is only needed if looking
|
|
96
|
-
* for a singular document.
|
|
97
|
-
* @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
|
|
98
|
-
* @returns {object} Parameters which can then be used with an allDocs request.
|
|
99
|
-
*/
|
|
100
|
-
function getDocParams(docType, docId = null, otherProps = {}) {
|
|
101
|
-
if (docId == null) {
|
|
102
|
-
docId = ""
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
...otherProps,
|
|
106
|
-
startkey: `${docType}${SEPARATOR}${docId}`,
|
|
107
|
-
endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}`,
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
69
|
exports.getDocParams = getDocParams
|
|
70
|
+
exports.getRowParams = getRowParams
|
|
71
|
+
exports.generateRowID = generateRowID
|
|
72
|
+
exports.getUserMetadataParams = getUserMetadataParams
|
|
73
|
+
exports.generateUserMetadataID = generateUserMetadataID
|
|
74
|
+
exports.getGlobalIDFromUserMetadataID = getGlobalIDFromUserMetadataID
|
|
112
75
|
|
|
113
76
|
/**
|
|
114
77
|
* Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
|
|
@@ -125,24 +88,6 @@ exports.generateTableID = () => {
|
|
|
125
88
|
return `${DocumentType.TABLE}${SEPARATOR}${newid()}`
|
|
126
89
|
}
|
|
127
90
|
|
|
128
|
-
/**
|
|
129
|
-
* Gets the DB allDocs/query params for retrieving a row.
|
|
130
|
-
* @param {string|null} tableId The table in which the rows have been stored.
|
|
131
|
-
* @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
|
|
132
|
-
* left null to get all the rows in the table.
|
|
133
|
-
* @param {object} otherProps Any other properties to add to the request.
|
|
134
|
-
* @returns {object} Parameters which can then be used with an allDocs request.
|
|
135
|
-
*/
|
|
136
|
-
exports.getRowParams = (tableId = null, rowId = null, otherProps = {}) => {
|
|
137
|
-
if (tableId == null) {
|
|
138
|
-
return getDocParams(DocumentType.ROW, null, otherProps)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId
|
|
142
|
-
|
|
143
|
-
return getDocParams(DocumentType.ROW, endOfKey, otherProps)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
91
|
/**
|
|
147
92
|
* Given a row ID this will find the table ID within it (only works for internal tables).
|
|
148
93
|
* @param {string} rowId The ID of the row.
|
|
@@ -155,44 +100,6 @@ exports.getTableIDFromRowID = rowId => {
|
|
|
155
100
|
return `${DocumentType.TABLE}${SEPARATOR}${components[0]}`
|
|
156
101
|
}
|
|
157
102
|
|
|
158
|
-
/**
|
|
159
|
-
* Gets a new row ID for the specified table.
|
|
160
|
-
* @param {string} tableId The table which the row is being created for.
|
|
161
|
-
* @param {string|null} id If an ID is to be used then the UUID can be substituted for this.
|
|
162
|
-
* @returns {string} The new ID which a row doc can be stored under.
|
|
163
|
-
*/
|
|
164
|
-
exports.generateRowID = (tableId, id = null) => {
|
|
165
|
-
id = id || newid()
|
|
166
|
-
return `${DocumentType.ROW}${SEPARATOR}${tableId}${SEPARATOR}${id}`
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Gets parameters for retrieving users, this is a utility function for the getDocParams function.
|
|
171
|
-
*/
|
|
172
|
-
exports.getUserMetadataParams = (userId = null, otherProps = {}) => {
|
|
173
|
-
return exports.getRowParams(InternalTables.USER_METADATA, userId, otherProps)
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Generates a new user ID based on the passed in global ID.
|
|
178
|
-
* @param {string} globalId The ID of the global user.
|
|
179
|
-
* @returns {string} The new user ID which the user doc can be stored under.
|
|
180
|
-
*/
|
|
181
|
-
exports.generateUserMetadataID = globalId => {
|
|
182
|
-
return exports.generateRowID(InternalTables.USER_METADATA, globalId)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Breaks up the ID to get the global ID.
|
|
187
|
-
*/
|
|
188
|
-
exports.getGlobalIDFromUserMetadataID = id => {
|
|
189
|
-
const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
|
|
190
|
-
if (!id || !id.includes(prefix)) {
|
|
191
|
-
return id
|
|
192
|
-
}
|
|
193
|
-
return id.split(prefix)[1]
|
|
194
|
-
}
|
|
195
|
-
|
|
196
103
|
/**
|
|
197
104
|
* Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
|
|
198
105
|
*/
|
|
@@ -27,18 +27,6 @@ export interface TriggerOutput {
|
|
|
27
27
|
timestamp?: number
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export interface AutomationEvent {
|
|
31
|
-
data: {
|
|
32
|
-
automation: Automation
|
|
33
|
-
event: any
|
|
34
|
-
}
|
|
35
|
-
opts?: {
|
|
36
|
-
repeat?: {
|
|
37
|
-
jobId: string
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
30
|
export interface AutomationContext extends AutomationResults {
|
|
43
31
|
steps: any[]
|
|
44
32
|
trigger: any
|
package/src/index.ts
CHANGED