Skip to content

Instantly share code, notes, and snippets.

@bushev
Created March 4, 2019 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bushev/d6b9a253ccd087196cb56a83e625b3d2 to your computer and use it in GitHub Desktop.
Save bushev/d6b9a253ccd087196cb56a83e625b3d2 to your computer and use it in GitHub Desktop.
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