@budibase/backend-core 3.2.4 → 3.2.6
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/dist/index.js.map +1 -1
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +11 -4
- package/dist/plugins.js.meta.json +1 -1
- package/package.json +11 -4
- package/src/accounts/accounts.ts +0 -82
- package/src/accounts/api.ts +0 -59
- package/src/accounts/index.ts +0 -1
- package/src/auth/auth.ts +0 -210
- package/src/auth/index.ts +0 -1
- package/src/auth/tests/auth.spec.ts +0 -14
- package/src/blacklist/blacklist.ts +0 -54
- package/src/blacklist/index.ts +0 -1
- package/src/blacklist/tests/blacklist.spec.ts +0 -46
- package/src/cache/appMetadata.ts +0 -88
- package/src/cache/base/index.ts +0 -150
- package/src/cache/docWritethrough.ts +0 -105
- package/src/cache/generic.ts +0 -33
- package/src/cache/index.ts +0 -8
- package/src/cache/invite.ts +0 -86
- package/src/cache/passwordReset.ts +0 -49
- package/src/cache/tests/docWritethrough.spec.ts +0 -296
- package/src/cache/tests/user.spec.ts +0 -145
- package/src/cache/tests/writethrough.spec.ts +0 -139
- package/src/cache/user.ts +0 -154
- package/src/cache/writethrough.ts +0 -133
- package/src/configs/configs.ts +0 -263
- package/src/configs/index.ts +0 -1
- package/src/configs/tests/configs.spec.ts +0 -184
- package/src/constants/db.ts +0 -75
- package/src/constants/index.ts +0 -2
- package/src/constants/misc.ts +0 -36
- package/src/context/Context.ts +0 -14
- package/src/context/identity.ts +0 -58
- package/src/context/index.ts +0 -3
- package/src/context/mainContext.ts +0 -422
- package/src/context/tests/index.spec.ts +0 -255
- package/src/context/types.ts +0 -26
- package/src/db/Replication.ts +0 -94
- package/src/db/couch/DatabaseImpl.ts +0 -511
- package/src/db/couch/connections.ts +0 -89
- package/src/db/couch/index.ts +0 -4
- package/src/db/couch/pouchDB.ts +0 -97
- package/src/db/couch/pouchDump.ts +0 -0
- package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
- package/src/db/couch/utils.ts +0 -55
- package/src/db/db.ts +0 -34
- package/src/db/errors.ts +0 -14
- package/src/db/index.ts +0 -12
- package/src/db/instrumentation.ts +0 -199
- package/src/db/lucene.ts +0 -721
- package/src/db/searchIndexes/index.ts +0 -1
- package/src/db/searchIndexes/searchIndexes.ts +0 -62
- package/src/db/tests/DatabaseImpl.spec.ts +0 -55
- package/src/db/tests/connections.spec.ts +0 -22
- package/src/db/tests/index.spec.ts +0 -32
- package/src/db/tests/lucene.spec.ts +0 -400
- package/src/db/tests/pouch.spec.js +0 -62
- package/src/db/tests/utils.spec.ts +0 -63
- package/src/db/utils.ts +0 -208
- package/src/db/views.ts +0 -245
- package/src/docIds/conversions.ts +0 -60
- package/src/docIds/ids.ts +0 -126
- package/src/docIds/index.ts +0 -2
- package/src/docIds/newid.ts +0 -5
- package/src/docIds/params.ts +0 -189
- package/src/docUpdates/index.ts +0 -24
- package/src/environment.ts +0 -293
- package/src/errors/errors.ts +0 -119
- package/src/errors/index.ts +0 -1
- package/src/events/analytics.ts +0 -6
- package/src/events/asyncEvents/index.ts +0 -2
- package/src/events/asyncEvents/publisher.ts +0 -12
- package/src/events/asyncEvents/queue.ts +0 -22
- package/src/events/backfill.ts +0 -183
- package/src/events/documentId.ts +0 -56
- package/src/events/events.ts +0 -47
- package/src/events/identification.ts +0 -311
- package/src/events/index.ts +0 -15
- package/src/events/processors/AnalyticsProcessor.ts +0 -64
- package/src/events/processors/AuditLogsProcessor.ts +0 -92
- package/src/events/processors/LoggingProcessor.ts +0 -36
- package/src/events/processors/Processors.ts +0 -52
- package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
- package/src/events/processors/index.ts +0 -19
- package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
- package/src/events/processors/posthog/index.ts +0 -3
- package/src/events/processors/posthog/rateLimiting.ts +0 -106
- package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
- package/src/events/processors/types.ts +0 -1
- package/src/events/publishers/account.ts +0 -41
- package/src/events/publishers/ai.ts +0 -21
- package/src/events/publishers/app.ts +0 -168
- package/src/events/publishers/auditLog.ts +0 -26
- package/src/events/publishers/auth.ts +0 -73
- package/src/events/publishers/automation.ts +0 -110
- package/src/events/publishers/backfill.ts +0 -74
- package/src/events/publishers/backup.ts +0 -42
- package/src/events/publishers/datasource.ts +0 -48
- package/src/events/publishers/email.ts +0 -17
- package/src/events/publishers/environmentVariable.ts +0 -38
- package/src/events/publishers/group.ts +0 -99
- package/src/events/publishers/index.ts +0 -25
- package/src/events/publishers/installation.ts +0 -38
- package/src/events/publishers/layout.ts +0 -26
- package/src/events/publishers/license.ts +0 -84
- package/src/events/publishers/org.ts +0 -37
- package/src/events/publishers/plugin.ts +0 -47
- package/src/events/publishers/query.ts +0 -89
- package/src/events/publishers/role.ts +0 -62
- package/src/events/publishers/rows.ts +0 -29
- package/src/events/publishers/screen.ts +0 -36
- package/src/events/publishers/serve.ts +0 -43
- package/src/events/publishers/table.ts +0 -70
- package/src/events/publishers/user.ts +0 -202
- package/src/events/publishers/view.ts +0 -107
- package/src/features/features.ts +0 -277
- package/src/features/index.ts +0 -2
- package/src/features/tests/features.spec.ts +0 -267
- package/src/features/tests/utils.ts +0 -64
- package/src/helpers.ts +0 -9
- package/src/index.ts +0 -59
- package/src/installation.ts +0 -115
- package/src/logging/alerts.ts +0 -26
- package/src/logging/correlation/correlation.ts +0 -15
- package/src/logging/correlation/index.ts +0 -1
- package/src/logging/correlation/middleware.ts +0 -18
- package/src/logging/index.ts +0 -4
- package/src/logging/pino/logger.ts +0 -239
- package/src/logging/pino/middleware.ts +0 -48
- package/src/logging/system.ts +0 -81
- package/src/logging/tests/system.spec.ts +0 -61
- package/src/middleware/adminOnly.ts +0 -9
- package/src/middleware/auditLog.ts +0 -6
- package/src/middleware/authenticated.ts +0 -247
- package/src/middleware/builderOnly.ts +0 -21
- package/src/middleware/builderOrAdmin.ts +0 -21
- package/src/middleware/contentSecurityPolicy.ts +0 -113
- package/src/middleware/csrf.ts +0 -81
- package/src/middleware/errorHandling.ts +0 -43
- package/src/middleware/index.ts +0 -24
- package/src/middleware/internalApi.ts +0 -23
- package/src/middleware/ip.ts +0 -12
- package/src/middleware/joi-validator.ts +0 -58
- package/src/middleware/matchers.ts +0 -39
- package/src/middleware/passport/datasource/google.ts +0 -102
- package/src/middleware/passport/local.ts +0 -54
- package/src/middleware/passport/sso/google.ts +0 -77
- package/src/middleware/passport/sso/oidc.ts +0 -152
- package/src/middleware/passport/sso/sso.ts +0 -138
- package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
- package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
- package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
- package/src/middleware/passport/utils.ts +0 -38
- package/src/middleware/querystringToBody.ts +0 -28
- package/src/middleware/tenancy.ts +0 -36
- package/src/middleware/tests/builder.spec.ts +0 -181
- package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
- package/src/middleware/tests/matchers.spec.ts +0 -100
- package/src/migrations/definitions.ts +0 -40
- package/src/migrations/index.ts +0 -2
- package/src/migrations/migrations.ts +0 -186
- package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
- package/src/migrations/tests/migrations.spec.ts +0 -64
- package/src/objectStore/buckets/app.ts +0 -53
- package/src/objectStore/buckets/global.ts +0 -29
- package/src/objectStore/buckets/index.ts +0 -3
- package/src/objectStore/buckets/plugins.ts +0 -71
- package/src/objectStore/buckets/tests/app.spec.ts +0 -161
- package/src/objectStore/buckets/tests/global.spec.ts +0 -74
- package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
- package/src/objectStore/cloudfront.ts +0 -41
- package/src/objectStore/index.ts +0 -3
- package/src/objectStore/objectStore.ts +0 -585
- package/src/objectStore/utils.ts +0 -113
- package/src/platform/index.ts +0 -3
- package/src/platform/platformDb.ts +0 -6
- package/src/platform/tenants.ts +0 -101
- package/src/platform/tests/tenants.spec.ts +0 -26
- package/src/platform/users.ts +0 -129
- package/src/plugin/index.ts +0 -1
- package/src/plugin/tests/validation.spec.ts +0 -209
- package/src/plugin/utils.ts +0 -175
- package/src/queue/constants.ts +0 -8
- package/src/queue/inMemoryQueue.ts +0 -189
- package/src/queue/index.ts +0 -2
- package/src/queue/listeners.ts +0 -199
- package/src/queue/queue.ts +0 -84
- package/src/redis/index.ts +0 -6
- package/src/redis/init.ts +0 -118
- package/src/redis/redis.ts +0 -358
- package/src/redis/redlockImpl.ts +0 -155
- package/src/redis/tests/redis.spec.ts +0 -207
- package/src/redis/tests/redlockImpl.spec.ts +0 -105
- package/src/redis/utils.ts +0 -128
- package/src/security/auth.ts +0 -24
- package/src/security/encryption.ts +0 -185
- package/src/security/index.ts +0 -1
- package/src/security/permissions.ts +0 -166
- package/src/security/roles.ts +0 -655
- package/src/security/secrets.ts +0 -20
- package/src/security/sessions.ts +0 -123
- package/src/security/tests/auth.spec.ts +0 -45
- package/src/security/tests/encryption.spec.ts +0 -31
- package/src/security/tests/permissions.spec.ts +0 -146
- package/src/security/tests/secrets.spec.ts +0 -35
- package/src/security/tests/sessions.spec.ts +0 -12
- package/src/sql/designDoc.ts +0 -17
- package/src/sql/index.ts +0 -5
- package/src/sql/sql.ts +0 -1854
- package/src/sql/sqlTable.ts +0 -319
- package/src/sql/utils.ts +0 -193
- package/src/tenancy/db.ts +0 -6
- package/src/tenancy/index.ts +0 -2
- package/src/tenancy/tenancy.ts +0 -148
- package/src/tenancy/tests/tenancy.spec.ts +0 -184
- package/src/timers/index.ts +0 -1
- package/src/timers/timers.ts +0 -22
- package/src/users/db.ts +0 -582
- package/src/users/events.ts +0 -176
- package/src/users/index.ts +0 -4
- package/src/users/lookup.ts +0 -99
- package/src/users/test/db.spec.ts +0 -188
- package/src/users/test/utils.spec.ts +0 -67
- package/src/users/users.ts +0 -353
- package/src/users/utils.ts +0 -81
- package/src/utils/Duration.ts +0 -56
- package/src/utils/hashing.ts +0 -15
- package/src/utils/index.ts +0 -4
- package/src/utils/stringUtils.ts +0 -8
- package/src/utils/tests/Duration.spec.ts +0 -19
- package/src/utils/tests/utils.spec.ts +0 -204
- package/src/utils/utils.ts +0 -249
- package/tests/core/logging.ts +0 -34
- package/tests/core/users/users.spec.js +0 -53
- package/tests/core/utilities/index.ts +0 -7
- package/tests/core/utilities/jestUtils.ts +0 -33
- package/tests/core/utilities/mocks/alerts.ts +0 -4
- package/tests/core/utilities/mocks/date.ts +0 -3
- package/tests/core/utilities/mocks/events.ts +0 -132
- package/tests/core/utilities/mocks/index.ts +0 -9
- package/tests/core/utilities/mocks/licenses.ts +0 -119
- package/tests/core/utilities/queue.ts +0 -9
- package/tests/core/utilities/structures/Chance.ts +0 -20
- package/tests/core/utilities/structures/accounts.ts +0 -80
- package/tests/core/utilities/structures/apps.ts +0 -21
- package/tests/core/utilities/structures/common.ts +0 -7
- package/tests/core/utilities/structures/db.ts +0 -12
- package/tests/core/utilities/structures/documents/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
- package/tests/core/utilities/structures/generator.ts +0 -3
- package/tests/core/utilities/structures/index.ts +0 -15
- package/tests/core/utilities/structures/koa.ts +0 -16
- package/tests/core/utilities/structures/licenses.ts +0 -190
- package/tests/core/utilities/structures/plugins.ts +0 -19
- package/tests/core/utilities/structures/quotas.ts +0 -72
- package/tests/core/utilities/structures/scim.ts +0 -80
- package/tests/core/utilities/structures/sso.ts +0 -118
- package/tests/core/utilities/structures/tenants.ts +0 -5
- package/tests/core/utilities/structures/userGroups.ts +0 -10
- package/tests/core/utilities/structures/users.ts +0 -89
- package/tests/core/utilities/testContainerUtils.ts +0 -165
- package/tests/core/utilities/utils/index.ts +0 -2
- package/tests/core/utilities/utils/queue.ts +0 -27
- package/tests/core/utilities/utils/time.ts +0 -3
- package/tests/extra/DBTestConfiguration.ts +0 -36
- package/tests/extra/index.ts +0 -2
- package/tests/extra/testEnv.ts +0 -95
- package/tests/index.ts +0 -2
- package/tests/jestEnv.ts +0 -10
- package/tests/jestSetup.ts +0 -36
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import events from "events"
|
|
2
|
-
import { newid } from "../utils"
|
|
3
|
-
import { Queue, QueueOptions, JobOptions } from "./queue"
|
|
4
|
-
|
|
5
|
-
interface JobMessage {
|
|
6
|
-
id: string
|
|
7
|
-
timestamp: number
|
|
8
|
-
queue: string
|
|
9
|
-
data: any
|
|
10
|
-
opts?: JobOptions
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Bull works with a Job wrapper around all messages that contains a lot more information about
|
|
15
|
-
* the state of the message, this object constructor implements the same schema of Bull jobs
|
|
16
|
-
* for the sake of maintaining API consistency.
|
|
17
|
-
* @param queue The name of the queue which the message will be carried on.
|
|
18
|
-
* @param message The JSON message which will be passed back to the consumer.
|
|
19
|
-
* @returns A new job which can now be put onto the queue, this is mostly an
|
|
20
|
-
* internal structure so that an in memory queue can be easily swapped for a Bull queue.
|
|
21
|
-
*/
|
|
22
|
-
function newJob(queue: string, message: any, opts?: JobOptions): JobMessage {
|
|
23
|
-
return {
|
|
24
|
-
id: newid(),
|
|
25
|
-
timestamp: Date.now(),
|
|
26
|
-
queue: queue,
|
|
27
|
-
data: message,
|
|
28
|
-
opts,
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* This is designed to replicate Bull (https://github.com/OptimalBits/bull) in memory as a sort of mock.
|
|
34
|
-
* It is relatively simple, using an event emitter internally to register when messages are available
|
|
35
|
-
* to the consumers - in can support many inputs and many consumers.
|
|
36
|
-
*/
|
|
37
|
-
class InMemoryQueue implements Partial<Queue> {
|
|
38
|
-
_name: string
|
|
39
|
-
_opts?: QueueOptions
|
|
40
|
-
_messages: JobMessage[]
|
|
41
|
-
_queuedJobIds: Set<string>
|
|
42
|
-
_emitter: NodeJS.EventEmitter
|
|
43
|
-
_runCount: number
|
|
44
|
-
_addCount: number
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* The constructor the queue, exactly the same as that of Bulls.
|
|
48
|
-
* @param name The name of the queue which is being configured.
|
|
49
|
-
* @param opts This is not used by the in memory queue as there is no real use
|
|
50
|
-
* case when in memory, but is the same API as Bull
|
|
51
|
-
*/
|
|
52
|
-
constructor(name: string, opts?: QueueOptions) {
|
|
53
|
-
this._name = name
|
|
54
|
-
this._opts = opts
|
|
55
|
-
this._messages = []
|
|
56
|
-
this._emitter = new events.EventEmitter()
|
|
57
|
-
this._runCount = 0
|
|
58
|
-
this._addCount = 0
|
|
59
|
-
this._queuedJobIds = new Set<string>()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Same callback API as Bull, each callback passed to this will consume messages as they are
|
|
64
|
-
* available. Please note this is a queue service, not a notification service, so each
|
|
65
|
-
* consumer will receive different messages.
|
|
66
|
-
* as the Bull API, within this job the property "data" contains the JSON message. Please
|
|
67
|
-
* note this is incredibly limited compared to Bull as in reality the Job would contain
|
|
68
|
-
* a lot more information about the queue and current status of Bull cluster.
|
|
69
|
-
*/
|
|
70
|
-
async process(concurrencyOrFunc: number | any, func?: any) {
|
|
71
|
-
func = typeof concurrencyOrFunc === "number" ? func : concurrencyOrFunc
|
|
72
|
-
this._emitter.on("message", async () => {
|
|
73
|
-
if (this._messages.length <= 0) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
let msg = this._messages.shift()
|
|
77
|
-
|
|
78
|
-
let resp = func(msg)
|
|
79
|
-
|
|
80
|
-
async function retryFunc(fnc: any) {
|
|
81
|
-
try {
|
|
82
|
-
await fnc
|
|
83
|
-
} catch (e: any) {
|
|
84
|
-
await new Promise<void>(r => setTimeout(() => r(), 50))
|
|
85
|
-
|
|
86
|
-
await retryFunc(func(msg))
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (resp.then != null) {
|
|
91
|
-
try {
|
|
92
|
-
await retryFunc(resp)
|
|
93
|
-
} catch (e: any) {
|
|
94
|
-
console.error(e)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
this._runCount++
|
|
98
|
-
const jobId = msg?.opts?.jobId?.toString()
|
|
99
|
-
if (jobId && msg?.opts?.removeOnComplete) {
|
|
100
|
-
this._queuedJobIds.delete(jobId)
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async isReady() {
|
|
106
|
-
return this as any
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// simply puts a message to the queue and emits to the queue for processing
|
|
110
|
-
/**
|
|
111
|
-
* Simple function to replicate the add message functionality of Bull, putting
|
|
112
|
-
* a new message on the queue. This then emits an event which will be used to
|
|
113
|
-
* return the message to a consumer (if one is attached).
|
|
114
|
-
* @param msg A message to be transported over the queue, this should be
|
|
115
|
-
* a JSON message as this is required by Bull.
|
|
116
|
-
* @param repeat serves no purpose for the import queue.
|
|
117
|
-
*/
|
|
118
|
-
async add(data: any, opts?: JobOptions) {
|
|
119
|
-
const jobId = opts?.jobId?.toString()
|
|
120
|
-
if (jobId && this._queuedJobIds.has(jobId)) {
|
|
121
|
-
console.log(`Ignoring already queued job ${jobId}`)
|
|
122
|
-
return
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (typeof data !== "object") {
|
|
126
|
-
throw "Queue only supports carrying JSON."
|
|
127
|
-
}
|
|
128
|
-
if (jobId) {
|
|
129
|
-
this._queuedJobIds.add(jobId)
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const pushMessage = () => {
|
|
133
|
-
this._messages.push(newJob(this._name, data, opts))
|
|
134
|
-
this._addCount++
|
|
135
|
-
this._emitter.emit("message")
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const delay = opts?.delay
|
|
139
|
-
if (delay) {
|
|
140
|
-
setTimeout(pushMessage, delay)
|
|
141
|
-
} else {
|
|
142
|
-
pushMessage()
|
|
143
|
-
}
|
|
144
|
-
return { id: jobId } as any
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* replicating the close function from bull, which waits for jobs to finish.
|
|
149
|
-
*/
|
|
150
|
-
async close() {}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* This removes a cron which has been implemented, this is part of Bull API.
|
|
154
|
-
* @param cronJobId The cron which is to be removed.
|
|
155
|
-
*/
|
|
156
|
-
async removeRepeatableByKey(cronJobId: string) {
|
|
157
|
-
// TODO: implement for testing
|
|
158
|
-
console.log(cronJobId)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Implemented for tests
|
|
163
|
-
*/
|
|
164
|
-
async getRepeatableJobs() {
|
|
165
|
-
return []
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async removeJobs(_pattern: string) {
|
|
169
|
-
// no-op
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Implemented for tests
|
|
174
|
-
*/
|
|
175
|
-
async clean() {
|
|
176
|
-
return []
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
async getJob() {
|
|
180
|
-
return null
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
on() {
|
|
184
|
-
// do nothing
|
|
185
|
-
return this as any
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export default InMemoryQueue
|
package/src/queue/index.ts
DELETED
package/src/queue/listeners.ts
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { Job, JobId, Queue } from "bull"
|
|
2
|
-
import { JobQueue } from "./constants"
|
|
3
|
-
import * as context from "../context"
|
|
4
|
-
|
|
5
|
-
export type StalledFn = (job: Job) => Promise<void>
|
|
6
|
-
|
|
7
|
-
export function addListeners(
|
|
8
|
-
queue: Queue,
|
|
9
|
-
jobQueue: JobQueue,
|
|
10
|
-
removeStalledCb?: StalledFn
|
|
11
|
-
) {
|
|
12
|
-
logging(queue, jobQueue)
|
|
13
|
-
if (removeStalledCb) {
|
|
14
|
-
handleStalled(queue, removeStalledCb)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function handleStalled(queue: Queue, removeStalledCb?: StalledFn) {
|
|
19
|
-
queue.on("stalled", async (job: Job) => {
|
|
20
|
-
if (removeStalledCb) {
|
|
21
|
-
await removeStalledCb(job)
|
|
22
|
-
} else if (job.opts.repeat) {
|
|
23
|
-
const jobId = job.id
|
|
24
|
-
const repeatJobs = await queue.getRepeatableJobs()
|
|
25
|
-
for (let repeatJob of repeatJobs) {
|
|
26
|
-
if (repeatJob.id === jobId) {
|
|
27
|
-
await queue.removeRepeatableByKey(repeatJob.key)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
console.log(`jobId=${jobId} disabled`)
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getLogParams(
|
|
36
|
-
eventType: QueueEventType,
|
|
37
|
-
event: BullEvent,
|
|
38
|
-
opts: {
|
|
39
|
-
job?: Job
|
|
40
|
-
jobId?: JobId
|
|
41
|
-
error?: Error
|
|
42
|
-
} = {},
|
|
43
|
-
extra: any = {}
|
|
44
|
-
) {
|
|
45
|
-
const message = `[BULL] ${eventType}=${event}`
|
|
46
|
-
const err = opts.error
|
|
47
|
-
|
|
48
|
-
const bullLog = {
|
|
49
|
-
_logKey: "bull",
|
|
50
|
-
eventType,
|
|
51
|
-
event,
|
|
52
|
-
job: opts.job,
|
|
53
|
-
jobId: opts.jobId || opts.job?.id,
|
|
54
|
-
...extra,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let automationLog
|
|
58
|
-
if (opts.job?.data?.automation) {
|
|
59
|
-
automationLog = {
|
|
60
|
-
_logKey: "automation",
|
|
61
|
-
trigger: opts.job
|
|
62
|
-
? opts.job.data.automation.definition.trigger.event
|
|
63
|
-
: undefined,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return [message, err, bullLog, automationLog]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
enum BullEvent {
|
|
71
|
-
ERROR = "error",
|
|
72
|
-
WAITING = "waiting",
|
|
73
|
-
ACTIVE = "active",
|
|
74
|
-
STALLED = "stalled",
|
|
75
|
-
PROGRESS = "progress",
|
|
76
|
-
COMPLETED = "completed",
|
|
77
|
-
FAILED = "failed",
|
|
78
|
-
PAUSED = "paused",
|
|
79
|
-
RESUMED = "resumed",
|
|
80
|
-
CLEANED = "cleaned",
|
|
81
|
-
DRAINED = "drained",
|
|
82
|
-
REMOVED = "removed",
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
enum QueueEventType {
|
|
86
|
-
AUTOMATION_EVENT = "automation-event",
|
|
87
|
-
APP_BACKUP_EVENT = "app-backup-event",
|
|
88
|
-
AUDIT_LOG_EVENT = "audit-log-event",
|
|
89
|
-
SYSTEM_EVENT = "system-event",
|
|
90
|
-
APP_MIGRATION = "app-migration",
|
|
91
|
-
DOC_WRITETHROUGH = "doc-writethrough",
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const EventTypeMap: { [key in JobQueue]: QueueEventType } = {
|
|
95
|
-
[JobQueue.AUTOMATION]: QueueEventType.AUTOMATION_EVENT,
|
|
96
|
-
[JobQueue.APP_BACKUP]: QueueEventType.APP_BACKUP_EVENT,
|
|
97
|
-
[JobQueue.AUDIT_LOG]: QueueEventType.AUDIT_LOG_EVENT,
|
|
98
|
-
[JobQueue.SYSTEM_EVENT_QUEUE]: QueueEventType.SYSTEM_EVENT,
|
|
99
|
-
[JobQueue.APP_MIGRATION]: QueueEventType.APP_MIGRATION,
|
|
100
|
-
[JobQueue.DOC_WRITETHROUGH_QUEUE]: QueueEventType.DOC_WRITETHROUGH,
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function logging(queue: Queue, jobQueue: JobQueue) {
|
|
104
|
-
const eventType = EventTypeMap[jobQueue]
|
|
105
|
-
|
|
106
|
-
function doInJobContext(job: Job, task: any) {
|
|
107
|
-
// if this is an automation job try to get the app id
|
|
108
|
-
const appId = job.data.event?.appId
|
|
109
|
-
if (appId) {
|
|
110
|
-
return context.doInContext(appId, task)
|
|
111
|
-
} else {
|
|
112
|
-
task()
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
queue
|
|
117
|
-
.on(BullEvent.STALLED, async (job: Job) => {
|
|
118
|
-
// A job has been marked as stalled. This is useful for debugging job
|
|
119
|
-
// workers that crash or pause the event loop.
|
|
120
|
-
await doInJobContext(job, () => {
|
|
121
|
-
console.error(...getLogParams(eventType, BullEvent.STALLED, { job }))
|
|
122
|
-
})
|
|
123
|
-
})
|
|
124
|
-
.on(BullEvent.ERROR, (error: any) => {
|
|
125
|
-
// An error occurred.
|
|
126
|
-
console.error(...getLogParams(eventType, BullEvent.ERROR, { error }))
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
if (process.env.NODE_DEBUG?.includes("bull")) {
|
|
130
|
-
queue
|
|
131
|
-
.on(BullEvent.WAITING, (jobId: JobId) => {
|
|
132
|
-
// A Job is waiting to be processed as soon as a worker is idling.
|
|
133
|
-
console.info(...getLogParams(eventType, BullEvent.WAITING, { jobId }))
|
|
134
|
-
})
|
|
135
|
-
.on(BullEvent.ACTIVE, async (job: Job) => {
|
|
136
|
-
// A job has started. You can use `jobPromise.cancel()`` to abort it.
|
|
137
|
-
await doInJobContext(job, () => {
|
|
138
|
-
console.info(...getLogParams(eventType, BullEvent.ACTIVE, { job }))
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
.on(BullEvent.PROGRESS, async (job: Job, progress: any) => {
|
|
142
|
-
// A job's progress was updated
|
|
143
|
-
await doInJobContext(job, () => {
|
|
144
|
-
console.info(
|
|
145
|
-
...getLogParams(
|
|
146
|
-
eventType,
|
|
147
|
-
BullEvent.PROGRESS,
|
|
148
|
-
{ job },
|
|
149
|
-
{ progress }
|
|
150
|
-
)
|
|
151
|
-
)
|
|
152
|
-
})
|
|
153
|
-
})
|
|
154
|
-
.on(BullEvent.COMPLETED, async (job: Job, result) => {
|
|
155
|
-
// A job successfully completed with a `result`.
|
|
156
|
-
await doInJobContext(job, () => {
|
|
157
|
-
console.info(
|
|
158
|
-
...getLogParams(eventType, BullEvent.COMPLETED, { job }, { result })
|
|
159
|
-
)
|
|
160
|
-
})
|
|
161
|
-
})
|
|
162
|
-
.on(BullEvent.FAILED, async (job: Job, error: any) => {
|
|
163
|
-
// A job failed with reason `err`!
|
|
164
|
-
await doInJobContext(job, () => {
|
|
165
|
-
console.error(
|
|
166
|
-
...getLogParams(eventType, BullEvent.FAILED, { job, error })
|
|
167
|
-
)
|
|
168
|
-
})
|
|
169
|
-
})
|
|
170
|
-
.on(BullEvent.PAUSED, () => {
|
|
171
|
-
// The queue has been paused.
|
|
172
|
-
console.info(...getLogParams(eventType, BullEvent.PAUSED))
|
|
173
|
-
})
|
|
174
|
-
.on(BullEvent.RESUMED, () => {
|
|
175
|
-
// The queue has been resumed.
|
|
176
|
-
console.info(...getLogParams(eventType, BullEvent.RESUMED))
|
|
177
|
-
})
|
|
178
|
-
.on(BullEvent.CLEANED, (jobs: Job[], type: string) => {
|
|
179
|
-
// Old jobs have been cleaned from the queue. `jobs` is an array of cleaned
|
|
180
|
-
// jobs, and `type` is the type of jobs cleaned.
|
|
181
|
-
console.info(
|
|
182
|
-
...getLogParams(
|
|
183
|
-
eventType,
|
|
184
|
-
BullEvent.CLEANED,
|
|
185
|
-
{},
|
|
186
|
-
{ length: jobs.length, type }
|
|
187
|
-
)
|
|
188
|
-
)
|
|
189
|
-
})
|
|
190
|
-
.on(BullEvent.DRAINED, () => {
|
|
191
|
-
// Emitted every time the queue has processed all the waiting jobs (even if there can be some delayed jobs not yet processed)
|
|
192
|
-
console.info(...getLogParams(eventType, BullEvent.DRAINED))
|
|
193
|
-
})
|
|
194
|
-
.on(BullEvent.REMOVED, (job: Job) => {
|
|
195
|
-
// A job successfully removed.
|
|
196
|
-
console.info(...getLogParams(eventType, BullEvent.REMOVED, { job }))
|
|
197
|
-
})
|
|
198
|
-
}
|
|
199
|
-
}
|
package/src/queue/queue.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import env from "../environment"
|
|
2
|
-
import { getRedisOptions } from "../redis/utils"
|
|
3
|
-
import { JobQueue } from "./constants"
|
|
4
|
-
import InMemoryQueue from "./inMemoryQueue"
|
|
5
|
-
import BullQueue, { QueueOptions, JobOptions } from "bull"
|
|
6
|
-
import { addListeners, StalledFn } from "./listeners"
|
|
7
|
-
import { Duration } from "../utils"
|
|
8
|
-
import * as timers from "../timers"
|
|
9
|
-
|
|
10
|
-
export { QueueOptions, Queue, JobOptions } from "bull"
|
|
11
|
-
|
|
12
|
-
// the queue lock is held for 5 minutes
|
|
13
|
-
const QUEUE_LOCK_MS = Duration.fromMinutes(5).toMs()
|
|
14
|
-
// queue lock is refreshed every 30 seconds
|
|
15
|
-
const QUEUE_LOCK_RENEW_INTERNAL_MS = Duration.fromSeconds(30).toMs()
|
|
16
|
-
// cleanup the queue every 60 seconds
|
|
17
|
-
const CLEANUP_PERIOD_MS = Duration.fromSeconds(60).toMs()
|
|
18
|
-
let QUEUES: BullQueue.Queue[] = []
|
|
19
|
-
let cleanupInterval: NodeJS.Timeout
|
|
20
|
-
|
|
21
|
-
async function cleanup() {
|
|
22
|
-
for (let queue of QUEUES) {
|
|
23
|
-
await queue.clean(CLEANUP_PERIOD_MS, "completed")
|
|
24
|
-
await queue.clean(CLEANUP_PERIOD_MS, "failed")
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function createQueue<T>(
|
|
29
|
-
jobQueue: JobQueue,
|
|
30
|
-
opts: {
|
|
31
|
-
removeStalledCb?: StalledFn
|
|
32
|
-
maxStalledCount?: number
|
|
33
|
-
jobOptions?: JobOptions
|
|
34
|
-
} = {}
|
|
35
|
-
): BullQueue.Queue<T> {
|
|
36
|
-
const redisOpts = getRedisOptions()
|
|
37
|
-
const queueConfig: QueueOptions = {
|
|
38
|
-
redis: redisOpts,
|
|
39
|
-
settings: {
|
|
40
|
-
maxStalledCount: opts.maxStalledCount ? opts.maxStalledCount : 0,
|
|
41
|
-
lockDuration: QUEUE_LOCK_MS,
|
|
42
|
-
lockRenewTime: QUEUE_LOCK_RENEW_INTERNAL_MS,
|
|
43
|
-
},
|
|
44
|
-
}
|
|
45
|
-
if (opts.jobOptions) {
|
|
46
|
-
queueConfig.defaultJobOptions = opts.jobOptions
|
|
47
|
-
}
|
|
48
|
-
let queue: BullQueue.Queue<T>
|
|
49
|
-
if (!env.isTest()) {
|
|
50
|
-
queue = new BullQueue(jobQueue, queueConfig)
|
|
51
|
-
} else if (
|
|
52
|
-
process.env.BULL_TEST_REDIS_PORT &&
|
|
53
|
-
!isNaN(+process.env.BULL_TEST_REDIS_PORT)
|
|
54
|
-
) {
|
|
55
|
-
queue = new BullQueue(jobQueue, {
|
|
56
|
-
redis: { host: "localhost", port: +process.env.BULL_TEST_REDIS_PORT },
|
|
57
|
-
})
|
|
58
|
-
} else {
|
|
59
|
-
queue = new InMemoryQueue(jobQueue, queueConfig) as any
|
|
60
|
-
}
|
|
61
|
-
addListeners(queue, jobQueue, opts?.removeStalledCb)
|
|
62
|
-
QUEUES.push(queue)
|
|
63
|
-
if (!cleanupInterval && !env.isTest()) {
|
|
64
|
-
cleanupInterval = timers.set(cleanup, CLEANUP_PERIOD_MS)
|
|
65
|
-
// fire off an initial cleanup
|
|
66
|
-
cleanup().catch(err => {
|
|
67
|
-
console.error(`Unable to cleanup ${jobQueue} initially - ${err}`)
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
return queue
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export async function shutdown() {
|
|
74
|
-
if (cleanupInterval) {
|
|
75
|
-
timers.clear(cleanupInterval)
|
|
76
|
-
}
|
|
77
|
-
if (QUEUES.length) {
|
|
78
|
-
for (let queue of QUEUES) {
|
|
79
|
-
await queue.close()
|
|
80
|
-
}
|
|
81
|
-
QUEUES = []
|
|
82
|
-
}
|
|
83
|
-
console.log("Queues shutdown")
|
|
84
|
-
}
|
package/src/redis/index.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// Mimic the outer package export for usage in index.ts
|
|
2
|
-
// The outer exports can't be used as they now reference dist directly
|
|
3
|
-
export { default as Client } from "./redis"
|
|
4
|
-
export * as utils from "./utils"
|
|
5
|
-
export * as clients from "./init"
|
|
6
|
-
export * as locks from "./redlockImpl"
|
package/src/redis/init.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import Client from "./redis"
|
|
2
|
-
import * as utils from "./utils"
|
|
3
|
-
|
|
4
|
-
let userClient: Client,
|
|
5
|
-
sessionClient: Client,
|
|
6
|
-
appClient: Client,
|
|
7
|
-
cacheClient: Client,
|
|
8
|
-
writethroughClient: Client,
|
|
9
|
-
lockClient: Client,
|
|
10
|
-
socketClient: Client,
|
|
11
|
-
inviteClient: Client,
|
|
12
|
-
passwordResetClient: Client,
|
|
13
|
-
docWritethroughClient: Client
|
|
14
|
-
|
|
15
|
-
export async function init() {
|
|
16
|
-
userClient = await new Client(utils.Databases.USER_CACHE).init()
|
|
17
|
-
sessionClient = await new Client(utils.Databases.SESSIONS).init()
|
|
18
|
-
appClient = await new Client(utils.Databases.APP_METADATA).init()
|
|
19
|
-
cacheClient = await new Client(utils.Databases.GENERIC_CACHE).init()
|
|
20
|
-
lockClient = await new Client(utils.Databases.LOCKS).init()
|
|
21
|
-
writethroughClient = await new Client(utils.Databases.WRITE_THROUGH).init()
|
|
22
|
-
inviteClient = await new Client(utils.Databases.INVITATIONS).init()
|
|
23
|
-
passwordResetClient = await new Client(utils.Databases.PW_RESETS).init()
|
|
24
|
-
socketClient = await new Client(
|
|
25
|
-
utils.Databases.SOCKET_IO,
|
|
26
|
-
utils.SelectableDatabase.SOCKET_IO
|
|
27
|
-
).init()
|
|
28
|
-
docWritethroughClient = await new Client(
|
|
29
|
-
utils.Databases.DOC_WRITE_THROUGH
|
|
30
|
-
).init()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function shutdown() {
|
|
34
|
-
if (userClient) await userClient.finish()
|
|
35
|
-
if (sessionClient) await sessionClient.finish()
|
|
36
|
-
if (appClient) await appClient.finish()
|
|
37
|
-
if (cacheClient) await cacheClient.finish()
|
|
38
|
-
if (writethroughClient) await writethroughClient.finish()
|
|
39
|
-
if (lockClient) await lockClient.finish()
|
|
40
|
-
if (inviteClient) await inviteClient.finish()
|
|
41
|
-
if (passwordResetClient) await passwordResetClient.finish()
|
|
42
|
-
if (socketClient) await socketClient.finish()
|
|
43
|
-
if (docWritethroughClient) await docWritethroughClient.finish()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
process.on("exit", async () => {
|
|
47
|
-
await shutdown()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
export async function getUserClient() {
|
|
51
|
-
if (!userClient) {
|
|
52
|
-
await init()
|
|
53
|
-
}
|
|
54
|
-
return userClient
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function getSessionClient() {
|
|
58
|
-
if (!sessionClient) {
|
|
59
|
-
await init()
|
|
60
|
-
}
|
|
61
|
-
return sessionClient
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function getAppClient() {
|
|
65
|
-
if (!appClient) {
|
|
66
|
-
await init()
|
|
67
|
-
}
|
|
68
|
-
return appClient
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export async function getCacheClient() {
|
|
72
|
-
if (!cacheClient) {
|
|
73
|
-
await init()
|
|
74
|
-
}
|
|
75
|
-
return cacheClient
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function getWritethroughClient() {
|
|
79
|
-
if (!writethroughClient) {
|
|
80
|
-
await init()
|
|
81
|
-
}
|
|
82
|
-
return writethroughClient
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export async function getLockClient() {
|
|
86
|
-
if (!lockClient) {
|
|
87
|
-
await init()
|
|
88
|
-
}
|
|
89
|
-
return lockClient
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function getSocketClient() {
|
|
93
|
-
if (!socketClient) {
|
|
94
|
-
await init()
|
|
95
|
-
}
|
|
96
|
-
return socketClient
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export async function getInviteClient() {
|
|
100
|
-
if (!inviteClient) {
|
|
101
|
-
await init()
|
|
102
|
-
}
|
|
103
|
-
return inviteClient
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export async function getPasswordResetClient() {
|
|
107
|
-
if (!passwordResetClient) {
|
|
108
|
-
await init()
|
|
109
|
-
}
|
|
110
|
-
return passwordResetClient
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export async function getDocWritethroughClient() {
|
|
114
|
-
if (!writethroughClient) {
|
|
115
|
-
await init()
|
|
116
|
-
}
|
|
117
|
-
return writethroughClient
|
|
118
|
-
}
|