@budibase/worker 3.12.6 → 3.12.7

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/nodemon.json CHANGED
@@ -5,7 +5,8 @@
5
5
  "../pro",
6
6
  "../types",
7
7
  "../shared-core",
8
- "../string-templates"
8
+ "../string-templates",
9
+ "../../.env"
9
10
  ],
10
11
  "ext": "js,ts,json",
11
12
  "ignore": ["**/*.spec.ts", "**/*.spec.js", "../*/dist/**/*"],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "3.12.6",
4
+ "version": "3.12.7",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -21,19 +21,10 @@
21
21
  "run:docker": "node dist/index.js",
22
22
  "debug": "yarn build && node --expose-gc --inspect=9223 dist/index.js",
23
23
  "run:docker:cluster": "pm2-runtime start pm2.config.js",
24
- "dev:stack:init": "node ./scripts/dev/manage.js init",
25
- "dev": "npm run dev:stack:init && nodemon",
26
- "dev:built": "yarn run dev:stack:init && yarn run run:docker",
24
+ "dev": "nodemon",
25
+ "dev:built": "yarn run run:docker",
27
26
  "test": "bash scripts/test.sh",
28
- "test:watch": "jest --watch",
29
- "env:multi:enable": "node scripts/multiTenancy.js enable",
30
- "env:multi:disable": "node scripts/multiTenancy.js disable",
31
- "env:selfhost:enable": "node scripts/selfhost.js enable",
32
- "env:selfhost:disable": "node scripts/selfhost.js disable",
33
- "env:localdomain:enable": "node scripts/localdomain.js enable",
34
- "env:localdomain:disable": "node scripts/localdomain.js disable",
35
- "env:account:enable": "node scripts/account.js enable",
36
- "env:account:disable": "node scripts/account.js disable"
27
+ "test:watch": "jest --watch"
37
28
  },
38
29
  "author": "Budibase",
39
30
  "license": "GPL-3.0",
@@ -102,8 +93,7 @@
102
93
  "superagent": "^10.1.1",
103
94
  "supertest": "6.3.3",
104
95
  "timekeeper": "2.2.0",
105
- "typescript": "5.7.2",
106
- "update-dotenv": "1.1.1"
96
+ "typescript": "5.7.2"
107
97
  },
108
98
  "resolutions": {
109
99
  "@budibase/pro": "npm:@budibase/pro@latest"
@@ -123,5 +113,5 @@
123
113
  }
124
114
  }
125
115
  },
126
- "gitHead": "a9dabfd71bc85ee7bff3ad4c1421e1478987d0a2"
116
+ "gitHead": "87d0fd4e2bfa88a5f45312ce133670856957b97b"
127
117
  }
@@ -1,14 +1,18 @@
1
1
  import { env as coreEnv } from "@budibase/backend-core"
2
2
  import { ServiceType } from "@budibase/types"
3
- import { join } from "path"
3
+ import { join, resolve } from "path"
4
4
  import cloneDeep from "lodash/cloneDeep"
5
5
 
6
6
  coreEnv._set("SERVICE_TYPE", ServiceType.WORKER)
7
7
 
8
+ const TOP_LEVEL_PATH =
9
+ process.env.TOP_LEVEL_PATH ||
10
+ process.env.WORKER_TOP_LEVEL_PATH ||
11
+ resolve(join(__dirname, "..", "..", ".."))
8
12
  let LOADED = false
9
13
  if (!LOADED && coreEnv.isDev() && !coreEnv.isTest()) {
10
14
  require("dotenv").config({
11
- path: join(__dirname, "..", ".env"),
15
+ path: join(TOP_LEVEL_PATH, ".env"),
12
16
  })
13
17
  LOADED = true
14
18
  }
@@ -40,6 +44,7 @@ const environment = {
40
44
  // prefer worker port to generic port
41
45
  PORT: process.env.WORKER_PORT || process.env.PORT,
42
46
  CLUSTER_PORT: process.env.CLUSTER_PORT,
47
+ WORKER_SERVICE: process.env.WORKER_SERVICE,
43
48
  // flags
44
49
  NODE_ENV: process.env.NODE_ENV,
45
50
  SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED || ""),
@@ -59,6 +64,7 @@ const environment = {
59
64
  SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
60
65
  ENCRYPTED_TEST_PUBLIC_API_KEY: process.env.ENCRYPTED_TEST_PUBLIC_API_KEY,
61
66
  SESSION_EXPIRY_SECONDS: process.env.SESSION_EXPIRY_SECONDS,
67
+ TOP_LEVEL_PATH: TOP_LEVEL_PATH,
62
68
  /**
63
69
  * Mock the email service in use - links to ethereal hosted emails are logged instead.
64
70
  */
package/src/index.ts CHANGED
@@ -85,10 +85,12 @@ app.use(api.routes())
85
85
 
86
86
  const server = http.createServer(app.callback())
87
87
 
88
- const shutdown = async () => {
89
- console.log("Worker service shutting down gracefully...")
88
+ const shutdown = async (signal?: string) => {
89
+ console.log(
90
+ `Worker service shutting down gracefully... ${signal ? `Signal: ${signal}` : ""}`
91
+ )
90
92
  timers.cleanup()
91
- events.shutdown()
93
+ await events.shutdown()
92
94
  await redis.clients.shutdown()
93
95
  await queue.shutdown()
94
96
  }
@@ -97,7 +99,7 @@ gracefulShutdown(server, {
97
99
  signals: "SIGINT SIGTERM",
98
100
  timeout: 30000,
99
101
  onShutdown: shutdown,
100
- forceExit: !env.isTest,
102
+ forceExit: !env.isTest(),
101
103
  finally: () => {
102
104
  console.log("Worker service shutdown complete")
103
105
  },
@@ -106,7 +108,7 @@ gracefulShutdown(server, {
106
108
  process.on("uncaughtException", async err => {
107
109
  logging.logAlert("Uncaught exception.", err)
108
110
  await shutdown()
109
- if (!env.isTest) {
111
+ if (!env.isTest()) {
110
112
  process.exit(1)
111
113
  }
112
114
  })
@@ -114,7 +116,7 @@ process.on("uncaughtException", async err => {
114
116
  process.on("unhandledRejection", async reason => {
115
117
  logging.logAlert("Unhandled Promise Rejection", reason as Error)
116
118
  await shutdown()
117
- if (!env.isTest) {
119
+ if (!env.isTest()) {
118
120
  process.exit(1)
119
121
  }
120
122
  })
@@ -37,10 +37,14 @@ import {
37
37
  } from "@budibase/types"
38
38
  import API from "./api"
39
39
  import jwt, { Secret } from "jsonwebtoken"
40
+ import http from "http"
40
41
 
41
42
  class TestConfiguration {
42
- server: any
43
- request: any
43
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse> =
44
+ undefined!
45
+
46
+ request: supertest.SuperTest<supertest.Test> = undefined!
47
+
44
48
  api: API
45
49
  tenantId: string
46
50
  user?: User
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- const updateDotEnv = require("update-dotenv")
3
-
4
- const arg = process.argv.slice(2)[0]
5
-
6
- updateDotEnv({
7
- DISABLE_ACCOUNT_PORTAL: arg === "enable" ? "" : "1",
8
- }).then(() => console.log("Updated worker!"))
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env node
2
- const { parsed: existingConfig } = require("dotenv").config()
3
- const updateDotEnv = require("update-dotenv")
4
-
5
- async function init() {
6
- let config = {
7
- SELF_HOSTED: "1",
8
- PORT: "4002",
9
- CLUSTER_PORT: "10000",
10
- JWT_SECRET: "testsecret",
11
- INTERNAL_API_KEY: "budibase",
12
- MINIO_ACCESS_KEY: "budibase",
13
- MINIO_SECRET_KEY: "budibase",
14
- REDIS_URL: "localhost:6379",
15
- REDIS_PASSWORD: "budibase",
16
- MINIO_URL: "http://localhost:4004",
17
- COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
18
- COUCH_DB_USERNAME: "budibase",
19
- COUCH_DB_PASSWORD: "budibase",
20
- // empty string is false
21
- MULTI_TENANCY: "",
22
- DISABLE_ACCOUNT_PORTAL: "1",
23
- ACCOUNT_PORTAL_URL: "http://localhost:10001",
24
- ACCOUNT_PORTAL_API_KEY: "budibase",
25
- PLATFORM_URL: "http://localhost:10000",
26
- APPS_URL: "http://localhost:4001",
27
- SERVICE: "worker-service",
28
- DEPLOYMENT_ENVIRONMENT: "development",
29
- ENABLE_EMAIL_TEST_MODE: "1",
30
- HTTP_LOGGING: "0",
31
- VERSION: "0.0.0+local",
32
- PASSWORD_MIN_LENGTH: "1",
33
- }
34
-
35
- config = { ...config, ...existingConfig }
36
-
37
- await updateDotEnv(config)
38
- }
39
-
40
- // if more than init required use this to determine the command type
41
- //const managementCommand = process.argv.slice(2)[0]
42
-
43
- // for now only one command
44
- let command = init
45
-
46
- command()
47
- .then(() => {
48
- console.log("Done! 🎉")
49
- })
50
- .catch(err => {
51
- console.error(
52
- "Something went wrong while managing budibase dev worker:",
53
- err.message
54
- )
55
- })
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env node
2
- const updateDotEnv = require("update-dotenv")
3
-
4
- const arg = process.argv.slice(2)[0]
5
- const isEnable = arg === "enable"
6
-
7
- let domain = process.argv.slice(2)[1]
8
- if (!domain) {
9
- domain = "local.com"
10
- }
11
-
12
- const getAccountPortalUrl = () => {
13
- if (isEnable) {
14
- return `http://account.${domain}:10001`
15
- } else {
16
- return `http://localhost:10001`
17
- }
18
- }
19
-
20
- const getBudibaseUrl = () => {
21
- if (isEnable) {
22
- return `http://${domain}:10000`
23
- } else {
24
- return `http://localhost:10000`
25
- }
26
- }
27
-
28
- const getCookieDomain = () => {
29
- if (isEnable) {
30
- return `.${domain}`
31
- } else {
32
- return ""
33
- }
34
- }
35
-
36
- /**
37
- * For testing multi tenancy sub domains locally.
38
- *
39
- * Relies on an entry in /etc/hosts e.g:
40
- *
41
- * 127.0.0.1 local.com
42
- *
43
- * and an entry for each tenant you wish to test locally e.g:
44
- *
45
- * 127.0.0.1 t1.local.com
46
- * 127.0.0.1 t2.local.com
47
- */
48
- updateDotEnv({
49
- ACCOUNT_PORTAL_URL: getAccountPortalUrl(),
50
- COOKIE_DOMAIN: getCookieDomain(),
51
- PLATFORM_URL: getBudibaseUrl(),
52
- }).then(() => console.log("Updated worker!"))
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- const updateDotEnv = require("update-dotenv")
3
-
4
- const arg = process.argv.slice(2)[0]
5
-
6
- updateDotEnv({
7
- MULTI_TENANCY: arg === "enable" ? "1" : "",
8
- }).then(() => console.log("Updated worker!"))
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env node
2
- const updateDotEnv = require("update-dotenv")
3
-
4
- const arg = process.argv.slice(2)[0]
5
-
6
- updateDotEnv({
7
- SELF_HOSTED: arg === "enable" ? "1" : "0",
8
- }).then(() => console.log("Updated worker!"))