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