-
Notifications
You must be signed in to change notification settings - Fork 4
RAINCATCH-652 - file-storage module initial implementation #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. Just a few comments.
| } | ||
| }; | ||
|
|
||
| var deferred = q.defer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are migrating to using bluebird vs q.deffered as it is an antipattern https://github.com/petkaantonov/bluebird/wiki/Promise-anti-patterns#the-deferred-anti-pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bluebird developer telling that q api is anti pattern is not surprising.
We need to migrate to bluebird, but possibly using similar patterns across the all modules. Let's address this in our backlog as there are multiple migration steps and we should be consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@witmicko KISS. We should not focus on choosing whats worse anti-pattern. If we need then we should create follow up task with refactoring after having POC that bluebird is our choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments. Generally looks good though.
lib/cloud/file-storage/awsStorage.js
Outdated
|
|
||
| var params = { | ||
| localFile: fileLocation, | ||
| ACL: 'authenticated-read', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be a constant?
| awsClient = s3.createClient(config); | ||
| } | ||
|
|
||
| function writeFile(namespace, fileName, fileLocation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use a comment here describing the function and parameters.
lib/cloud/file-storage/awsStorage.js
Outdated
| console.log(err); | ||
| deferred.reject(err.stack); | ||
| }); | ||
| uploader.on('progress', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we doing anything with this progress event? If not we can probably remove the listener.
lib/cloud/file-storage/awsStorage.js
Outdated
| Key: file | ||
| }; | ||
| try { | ||
| var buffer = awsClient.downloadStream(paramsStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a buffer or a stream ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ReadableStream :)
| if (!config || !config.mongoUrl) { | ||
| throw Error("Missing mongoUrl parameter for GridFs storage"); | ||
| } | ||
| MongoClient.connect(config.mongoUrl, function(err, connection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be passing back a Promise as MongoClient.connect is asynchronous?
| } | ||
|
|
||
| function writeFile(namespace, fileName, fileLocation) { | ||
| if (!gfs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think gfs should be a promise to take account of the async mongo connection.
Then you could have gfs.then(...)
package.json
Outdated
| "license": "MIT", | ||
| "dependencies": { | ||
| "debug": "^2.6.3", | ||
| "fh-wfm-mediator": "0.3.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fh-wfm-mediator is a devDependency as the mediator is passed from the consuming application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally looks good. Would be good to add some unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, small comments, needs to be validated and then unit tests added
| ```javascript | ||
| var parameters = { | ||
| // File namespace (folder) | ||
| namespace:null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what means null as namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default (root), no namespace etc.
| @@ -0,0 +1 @@ | |||
| // TODO Add code to support offline storage capabilities for client applications. No newline at end of file | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create JIRA for this task and put here JIRA#
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is jira and I'm going to work on this after merging this PR
| } | ||
| }; | ||
|
|
||
| var deferred = q.defer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@witmicko KISS. We should not focus on choosing whats worse anti-pattern. If we need then we should create follow up task with refactoring after having POC that bluebird is our choice
4b12220 to
ebabfc5
Compare
Motivation
Initial implementation of the file storage solution interface.
Interface initializes different client depending on the configuration passed in application.
Supported storage engineers:
Storage engine would be enabled only when file module would have flag in config set to true:
If flag is set to false files would be served from temporary storage (this would be used for demo apps for convenience and simplified setup). Alternative would be to have some localFile storage engine.
Notes
Implementation requires local file to be cached.
Buffer support on the way here: andrewrk/node-s3-client#154