Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
do not watch the storage buckets if data store scan is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
greyarch committed Jun 7, 2017
1 parent 6c98594 commit 32286c2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docker-dashboard-agent-compose",
"version": "3.2.0",
"version": "3.2.1",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 6 additions & 7 deletions src/coffee/storage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ lib = require './storage/lib.coffee'

module.exports = (agent, mqtt, config) ->

if config.datastore?.scanEnabled
lib.runPeriodically lib.publishDataStoreUsage(mqtt, '/agent/storage/size', config.dataDir)
lib.runPeriodically lib.publishDataStoreUsage(mqtt, '/agent/docker/graph', config.docker.graph.path)

publishStorageBuckets = (err, buckets) ->
mqtt.publish '/agent/storage/buckets', buckets unless err


basePath = path.join config.dataDir, config.domain

lib.listStorageBuckets fs, basePath, publishStorageBuckets
fs.watch basePath, (eventType, filename) ->
if config.datastore?.scanEnabled
lib.runPeriodically lib.publishDataStoreUsage(mqtt, '/agent/storage/size', config.dataDir)
lib.runPeriodically lib.publishDataStoreUsage(mqtt, '/agent/docker/graph', config.docker.graph.path)

lib.listStorageBuckets fs, basePath, publishStorageBuckets
fs.watch basePath, (eventType, filename) ->
lib.listStorageBuckets fs, basePath, publishStorageBuckets

agent.on '/storage/list', (params, data, callback) ->
lib.listStorageBuckets fs, basePath, (err, buckets) ->
Expand Down
19 changes: 17 additions & 2 deletions tests/coffee/storage.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,30 @@ describe 'Storage', ->
td.verify storageLib.publishDataStoreUsage(), {times: 0, ignoreExtraArgs: true}
td.verify storageLib.runPeriodically(), {times: 0, ignoreExtraArgs: true}

it 'should watch for changes on the base path and publish storage buckets', ->
it 'should watch for changes on the base path and publish storage buckets when data store scan is enabled', ->
agent = td.object ['on']
mqtt = td.object ['publish']
argIsFs = td.matchers.argThat (arg) -> arg is fs
captor = td.matchers.captor()

storage agent, mqtt, dataDir: '/rootDir', domain: 'myDomain', docker: graph: path: '/docker/graph'
storage agent, mqtt,
dataDir: '/rootDir'
domain: 'myDomain'
docker: graph: path: '/docker/graph'
datastore: scanEnabled: true
td.verify fs.watch '/rootDir/myDomain', captor.capture()
captor.value()
td.verify storageLib.listStorageBuckets argIsFs, '/rootDir/myDomain', captor.capture()
captor.value null, 'some-buckets'
td.verify mqtt.publish '/agent/storage/buckets', 'some-buckets'

it 'should NOT watch for changes on the base path and publish storage buckets when data store scan is disabled', ->
agent = td.object ['on']

storage agent, null,
dataDir: '/rootDir'
domain: 'myDomain'
docker: graph: path: '/docker/graph'
datastore: scanEnabled: false
td.verify fs.watch(), {times: 0, ignoreExtraArgs: true}
td.verify storageLib.listStorageBuckets(), {times: 0, ignoreExtraArgs: true}

0 comments on commit 32286c2

Please sign in to comment.