Skip to content

Commit

Permalink
Add env var to disable rehydrate (#1367)
Browse files Browse the repository at this point in the history
* add env var to disable rehydrate

* inverting disableRehydrate->enableRehydrate + setting default true

* adding enable env var into RehydrateIpfsQueue instead of routes
  • Loading branch information
vicky-g committed Apr 2, 2021
1 parent 2971439 commit ee5ba82
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
3 changes: 2 additions & 1 deletion creator-node/compose/env/base.env
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ debounceTime=5000
# Can be overriden.
creatorNodeIsDebug=true

WAIT_HOSTS=
WAIT_HOSTS=
enableRehydrate=true
45 changes: 25 additions & 20 deletions creator-node/src/RehydrateIpfsQueue.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Bull = require('bull')
const config = require('./config')
const { rehydrateIpfsFromFsIfNecessary, rehydrateIpfsDirFromFsIfNecessary } = require('./utils')
const { logger: genericLogger } = require('./logging')
const config = require('./config')
const enableRehydrate = config.get('enableRehydrate')

const PROCESS_NAMES = Object.freeze({
rehydrate_dir: 'rehydrate_dir',
Expand Down Expand Up @@ -53,7 +54,7 @@ class RehydrateIpfsQueue {
}
})

this.addRehydrateIpfsFromFsTask = this.addRehydrateIpfsFromFsIfNecessaryTask.bind(this)
this.addRehydrateIpfsFromFsIfNecessaryTask = this.addRehydrateIpfsFromFsIfNecessaryTask.bind(this)
this.addRehydrateIpfsDirFromFsIfNecessaryTask = this.addRehydrateIpfsDirFromFsIfNecessaryTask.bind(this)
}

Expand All @@ -75,16 +76,18 @@ class RehydrateIpfsQueue {
* @param {object} logContext
*/
async addRehydrateIpfsFromFsIfNecessaryTask (multihash, storagePath, { logContext }, filename = null) {
this.logStatus(logContext, 'Adding a rehydrateIpfsFromFsIfNecessary task to the queue!')
const count = await this.queue.count()
if (count > MAX_COUNT) return
const job = await this.queue.add(
PROCESS_NAMES.rehydrate_file,
{ multihash, storagePath, filename, logContext }
)
this.logStatus(logContext, 'Successfully added a rehydrateIpfsFromFsIfNecessary task!')
if (enableRehydrate) {
this.logStatus(logContext, 'Adding a rehydrateIpfsFromFsIfNecessary task to the queue!')
const count = await this.queue.count()
if (count > MAX_COUNT) return
const job = await this.queue.add(
PROCESS_NAMES.rehydrate_file,
{ multihash, storagePath, filename, logContext }
)
this.logStatus(logContext, 'Successfully added a rehydrateIpfsFromFsIfNecessary task!')

return job
return job
}
}

/**
Expand All @@ -93,16 +96,18 @@ class RehydrateIpfsQueue {
* @param {object} logContext
*/
async addRehydrateIpfsDirFromFsIfNecessaryTask (multihash, { logContext }) {
this.logStatus(logContext, 'Adding a rehydrateIpfsDirFromFsIfNecessary task to the queue!')
const count = await this.queue.count()
if (count > MAX_COUNT) return
const job = await this.queue.add(
PROCESS_NAMES.rehydrate_dir,
{ multihash, logContext }
)
this.logStatus(logContext, 'Successfully added a rehydrateIpfsDirFromFsIfNecessary task!')
if (enableRehydrate) {
this.logStatus(logContext, 'Adding a rehydrateIpfsDirFromFsIfNecessary task to the queue!')
const count = await this.queue.count()
if (count > MAX_COUNT) return
const job = await this.queue.add(
PROCESS_NAMES.rehydrate_dir,
{ multihash, logContext }
)
this.logStatus(logContext, 'Successfully added a rehydrateIpfsDirFromFsIfNecessary task!')

return job
return job
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion creator-node/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,17 @@ const config = convict({
env: 'maxStorageUsedPercent',
default: 95
},

pinAddCIDs: {
doc: 'Array of comma separated CIDs to pin',
format: String,
env: 'pinAddCIDs',
default: ''
},
enableRehydrate: {
doc: 'Flag to enable or disable rehydrate',
format: Boolean,
env: 'enableRehydrate',
default: true
}

// unsupported options at the moment
Expand Down

0 comments on commit ee5ba82

Please sign in to comment.