Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ActionHero Example Task: CleanLogFiles
var fs = require('fs');
var maxLogFileSize = '100000';
exports.task = {
name: 'cleanLogFiles',
description: 'I will clean (delete) all log files if they get to big',
frequency: 60 * 60 * 1000,
queue: 'default',
plugins: [],
pluginOptions: {},
run: function(api, params, next){
fs.readdirSync(api.config.paths.log).forEach( function(file){
file = api.config.log.logFolder + "/" + file;
fs.exists(file, function (exists){
if(exists){
size = fs.statSync(file).size;
if(size >= maxLogFileSize)
{
api.log(file + " is larger than " + maxLogFileSize + " bytes. Deleting.", "info");
fs.unlinkSync(file);
}
}
});
});
next(null);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment