diff --git a/libV2/tasks/BaseTask.js b/libV2/tasks/BaseTask.js index 6464fa3d..20bbfc62 100644 --- a/libV2/tasks/BaseTask.js +++ b/libV2/tasks/BaseTask.js @@ -117,18 +117,20 @@ class BaseTask extends Process { } get schedule() { - if (this._program.now) { + const opts = this._program.opts(); + if (opts.now) { return Now; } - if (this._program.schedule) { - return this._program.schedule; + if (opts.schedule) { + return opts.schedule; } return this._defaultSchedule; } get lag() { - if (this._program.lag !== undefined) { - return this._program.lag; + const opts = this._program.opts(); + if (opts.lag !== undefined) { + return opts.lag; } return this._defaultLag; } diff --git a/libV2/tasks/DiskUsage.js b/libV2/tasks/DiskUsage.js index cf38102b..2d97e4cb 100644 --- a/libV2/tasks/DiskUsage.js +++ b/libV2/tasks/DiskUsage.js @@ -131,15 +131,15 @@ class MonitorDiskUsage extends BaseTask { } get isLeader() { - return this._program.leader !== undefined; + return this._program.opts().leader !== undefined; } get isManualUnlock() { - return this._program.unlock !== undefined; + return this._program.opts().unlock !== undefined; } get isManualLock() { - return this._program.lock !== undefined; + return this._program.opts().lock !== undefined; } async _getUsage(path) { diff --git a/libV2/tasks/ManualAdjust.js b/libV2/tasks/ManualAdjust.js index a9ed0add..639b26ae 100644 --- a/libV2/tasks/ManualAdjust.js +++ b/libV2/tasks/ManualAdjust.js @@ -26,9 +26,10 @@ class ManualAdjust extends BaseTask { } async _start() { + const opts = this._program.opts(); this._utapiClient = new UtapiClient({ - host: this._program.host, - port: this._program.port, + host: opts.host, + port: opts.port, disableRetryCache: true, }); await super._start(); @@ -42,38 +43,39 @@ class ManualAdjust extends BaseTask { async _execute() { const timestamp = Date.now(); - const objectDelta = this._program.objects; - const sizeDelta = this._program.storage; + const opts = this._program.opts(); + const objectDelta = opts.objects; + const sizeDelta = opts.storage; - if (!this._program.bucket.length && !this._program.account.length && !this._program.user.length) { + if (!opts.bucket.length && !opts.account.length && !opts.user.length) { throw Error('You must provided at least one of --bucket, --account or --user'); } logger.info('writing adjustments'); - if (this._program.bucket.length) { + if (opts.bucket.length) { logger.info('adjusting buckets'); await async.eachSeries( - this._program.bucket, + opts.bucket, async bucket => this._pushAdjustmentMetric({ bucket, objectDelta, sizeDelta, timestamp, }), ); } - if (this._program.account.length) { + if (opts.account.length) { logger.info('adjusting accounts'); await async.eachSeries( - this._program.account, + opts.account, async account => this._pushAdjustmentMetric({ account, objectDelta, sizeDelta, timestamp, }), ); } - if (this._program.user.length) { + if (opts.user.length) { logger.info('adjusting users'); await async.eachSeries( - this._program.user, + opts.user, async user => this._pushAdjustmentMetric({ user, objectDelta, sizeDelta, timestamp, }), diff --git a/libV2/tasks/Reindex.js b/libV2/tasks/Reindex.js index 7319c07f..c60f80ec 100644 --- a/libV2/tasks/Reindex.js +++ b/libV2/tasks/Reindex.js @@ -158,8 +158,9 @@ class ReindexTask extends BaseTask { } get targetBuckets() { - if (this._program.bucket.length) { - return this._program.bucket.map(name => ({ name })); + const opts = this._program.opts(); + if (opts.bucket.length) { + return opts.bucket.map(name => ({ name })); } return metadata.listBuckets(); } diff --git a/package.json b/package.json index d1f24e71..37c2bb9e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "engines": { "node": ">=22" }, - "version": "8.2.4", + "version": "8.2.5", "description": "API for tracking resource utilization and reporting metrics", "main": "index.js", "repository": { diff --git a/tests/functional/softLimit/testSoftLimit.js b/tests/functional/softLimit/testSoftLimit.js index fc90b91d..ed174c83 100644 --- a/tests/functional/softLimit/testSoftLimit.js +++ b/tests/functional/softLimit/testSoftLimit.js @@ -17,7 +17,7 @@ describe('Test MonitorDiskUsage soft limit', function () { task = new MonitorDiskUsage({ warp10: warp10Clients }); await task.setup(); task._expirationEnabled = true; - task._program.leader = true; + task._program.opts = () => ({ leader: true }); }); afterEach(async () => { diff --git a/tests/functional/v2/server/testGetStorage.js b/tests/functional/v2/server/testGetStorage.js index a24f8097..fb98ddd2 100644 --- a/tests/functional/v2/server/testGetStorage.js +++ b/tests/functional/v2/server/testGetStorage.js @@ -49,7 +49,7 @@ describe('Test getStorage handler', function () { await cacheClient.connect(); ingestTask = new IngestShard({ warp10: [warp10Clients[0]] }); - ingestTask._program = { lag: 0 }; + ingestTask._program = { opts: () => ({ lag: 0 }) }; await ingestTask._cache.connect(); }); diff --git a/tests/functional/v2/task/testCreateCheckpoint.js b/tests/functional/v2/task/testCreateCheckpoint.js index 248d42ad..27025cdf 100644 --- a/tests/functional/v2/task/testCreateCheckpoint.js +++ b/tests/functional/v2/task/testCreateCheckpoint.js @@ -52,7 +52,7 @@ describe('Test CreateCheckpoint', function () { warp10 = new Warp10Client({ nodeId: prefix }); checkpointTask = new CreateCheckpoint({ warp10: [warp10], enableMetrics: true }); await checkpointTask.setup(); - checkpointTask._program = { lag: 0, nodeId: prefix }; + checkpointTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) }; }); afterEach(async () => { diff --git a/tests/functional/v2/task/testCreateSnapshot.js b/tests/functional/v2/task/testCreateSnapshot.js index fd288446..b26c9e4c 100644 --- a/tests/functional/v2/task/testCreateSnapshot.js +++ b/tests/functional/v2/task/testCreateSnapshot.js @@ -53,14 +53,14 @@ describe('Test CreateSnapshot', function () { warp10 = new Warp10Client({ nodeId: prefix }); checkpointTask = new CreateCheckpoint({ warp10: [warp10] }); - checkpointTask._program = { lag: 0, nodeId: prefix }; + checkpointTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) }; snapshotTask = new CreateSnapshot({ warp10: [warp10], enableMetrics: true }); await snapshotTask.setup(); - snapshotTask._program = { lag: 0, nodeId: prefix }; + snapshotTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) }; repairTask = new RepairTask({ warp10: [warp10] }); - repairTask._program = { lag: 0, nodeId: prefix }; + repairTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) }; }); afterEach(async () => { diff --git a/tests/functional/v2/task/testIngestShards.js b/tests/functional/v2/task/testIngestShards.js index af943a3b..f48e6cba 100644 --- a/tests/functional/v2/task/testIngestShards.js +++ b/tests/functional/v2/task/testIngestShards.js @@ -62,7 +62,7 @@ describe('Test IngestShards', function () { ingestTask = new IngestShard({ warp10: [warp10], enableMetrics: true }); await ingestTask.setup(); ingestTask._cache._cacheBackend._prefix = prefix; - ingestTask._program = { lag: 0 }; + ingestTask._program = { opts: () => ({ lag: 0 }) }; await ingestTask._cache.connect(); }); diff --git a/tests/functional/v2/task/testReindex.js b/tests/functional/v2/task/testReindex.js index d7041726..0371c603 100644 --- a/tests/functional/v2/task/testReindex.js +++ b/tests/functional/v2/task/testReindex.js @@ -38,7 +38,7 @@ describe('Test ReindexTask', function () { prefix = uuid(); warp10 = new Warp10Client({ nodeId: prefix }); reindexTask = new ReindexTask({ warp10: [warp10] }); - reindexTask._program = { bucket: [], nodeId: prefix }; + reindexTask._program = { opts: () => ({ bucket: [], nodeId: prefix }) }; }); afterEach(() => { diff --git a/tests/functional/v2/task/testRepair.js b/tests/functional/v2/task/testRepair.js index e6d13545..68bb0ff0 100644 --- a/tests/functional/v2/task/testRepair.js +++ b/tests/functional/v2/task/testRepair.js @@ -52,7 +52,7 @@ describe('Test Repair', function () { warp10 = new Warp10Client({ nodeId: prefix }); repairTask = new RepairTask({ warp10: [warp10], enableMetrics: true }); await repairTask.setup(); - repairTask._program = { lag: 0, nodeId: prefix }; + repairTask._program = { opts: () => ({ lag: 0, nodeId: prefix }) }; }); afterEach(async () => { diff --git a/tests/functional/v2/testClient.js b/tests/functional/v2/testClient.js index 33307306..4913581f 100644 --- a/tests/functional/v2/testClient.js +++ b/tests/functional/v2/testClient.js @@ -219,7 +219,7 @@ describe('Test UtapiClient', function () { await cacheClient.connect(); ingestTask = new IngestShard({ warp10: [warp10] }); - ingestTask._program = { lag: 0 }; + ingestTask._program = { opts: () => ({ lag: 0 }) }; await ingestTask._cache.connect(); }); @@ -245,4 +245,3 @@ describe('Test UtapiClient', function () { }); }); }); -