Created
March 4, 2019 01:55
-
-
Save bushev/d6b9a253ccd087196cb56a83e625b3d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Service } = require('moleculer'); | |
const compressFileHelper = require('../utils/compress-file'); | |
class CompressorService extends Service { | |
constructor(broker) { | |
super(broker); | |
this.parseServiceSchema({ | |
name: 'compressor', | |
actions: { | |
compress: { | |
params: { | |
filePath: 'string' | |
}, | |
handler: this.compress | |
} | |
}, | |
created: this.serviceCreated | |
}); | |
} | |
compress(ctx) { | |
return this.compressFile(ctx.params.filePath); | |
} | |
serviceCreated() { | |
this.logger.info(`Compressor Service created. PID ${process.pid}`); | |
} | |
compressFile(filePath) { | |
// Helper method: Compress file, return: optimizedPath, sizeIn, sizeOut, percent | |
return compressFileHelper(filePath); | |
} | |
} | |
module.exports = CompressorService; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment