Skip to content

Commit

Permalink
feat(studio): allow disabling file listeners for read-only deployments (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvitora committed Mar 15, 2022
1 parent c13b5c4 commit efad392
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/studio-be/src/core/bpfs/cache-invalidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TYPES } from 'core/app/types'
import { forceForwardSlashes } from 'core/misc/utils'
import { inject, injectable, tagged } from 'inversify'
import path from 'path'
import yn from 'yn'

export namespace CacheInvalidators {
enum ChangeEventAction {
Expand Down Expand Up @@ -46,25 +47,30 @@ export namespace CacheInvalidators {
install(objectCache: ObjectCache) {
this.cache = objectCache

// Support for Read-only Deployments (ROD)
if (yn(process.env.CORE_DISABLE_FILE_LISTENERS)) {
return
}

const foldersToWatch = [path.join(process.DATA_LOCATION, 'bots'), path.join(process.DATA_LOCATION, 'global')]

const watcher = chokidar.watch(foldersToWatch, {
ignoreInitial: true,
ignorePermissionErrors: true,
ignored: (path) => path.includes('node_modules')
ignored: path => path.includes('node_modules')
})

watcher.on('add', this.handle)
watcher.on('change', this.handle)
watcher.on('unlink', this.handle)
watcher.on('error', (err) => this.logger.attachError(err).error('Watcher error'))
watcher.on('error', err => this.logger.attachError(err).error('Watcher error'))
}

async stop() {
await this.watcher.stop()
}

handle = async (file) => {
handle = async file => {
if (!this.cache) {
return
}
Expand Down
5 changes: 5 additions & 0 deletions packages/studio-be/src/typings/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ declare interface BotpressEnvironmentVariables {
*/
readonly BP_ENABLED_MODULES?: string
readonly BP_DEBUG_SEGMENT?: boolean

/**
* Supports read-only deployments by allowing disabling file listeners
*/
readonly CORE_DISABLE_FILE_LISTENERS?: boolean
}

interface IDebug {
Expand Down

0 comments on commit efad392

Please sign in to comment.