Skip to content

Instantly share code, notes, and snippets.

@evantahler
Last active December 8, 2016 16:36
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 evantahler/5f427cde60f2f88ad61b to your computer and use it in GitHub Desktop.
Save evantahler/5f427cde60f2f88ad61b to your computer and use it in GitHub Desktop.
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