Permalink
Browse files

Quartz job was always running when Quartz was installed. Changed it t…

…o only run when the application's name is 'uploadr' and the environment is either development or 'ci'. Resolves #7
  • Loading branch information...
1 parent 2ea4bbb commit 83af0849e86d7e16ad75c9380e84dea6fc905886 @4np committed Mar 25, 2013
View
2 UploadrGrailsPlugin.groovy
@@ -15,7 +15,7 @@
* limitations under the License.
*/
class UploadrGrailsPlugin {
- def version = "0.7.0.1"
+ def version = "0.7.1"
def grailsVersion = "1.3.7 > *"
def dependsOn = [
jquery: "1.4 > *",
View
2 grails-app/conf/Config.groovy
@@ -29,3 +29,5 @@ grails.views.gsp.encoding="UTF-8"
uploadr.defaultUploadPath="${System.getProperty('user.home')}/Downloads/uploadr"
// used by the cleanUploadedFilesJob Quartz job (on ci and development)
uploadr.maxAgeUploadedFile=1000 * 60 * 60 * 4 // 4 hours in milliseconds
+// check if the cleanup job should run or not
+uploadr.cleanupJobEnabled=(grailsApplication.metadata['app.name'] == 'uploadr' && System.getProperty("grails.env") in ["ci","development"])
View
58 grails-app/jobs/hungry/wombat/CleanUploadedFilesJob.groovy
@@ -14,44 +14,48 @@ class CleanUploadedFilesJob {
}
def execute() {
+ def jobEnabled = grailsApplication.config.uploadr.cleanupJobEnabled
def fileExpiry = grailsApplication.config.uploadr.maxAgeUploadedFile // in milliseconds
def currentDate = new Date().getTime()
def uploadPath = new File(grailsApplication.config.uploadr.defaultUploadPath)
def dirsToDelete= []
- // does the upload path exist?
- if (uploadPath.exists() && uploadPath.isDirectory()) {
- // yes, iterate recursively over files
- uploadPath.eachFileRecurse { file ->
- if (file.exists()) {
- if (file.isFile() && currentDate > (file.lastModified() + fileExpiry)) {
- // file is older than threshold, delete it
- def parentFile = file.getParentFile()
-
- if (file.delete()) {
- log.info "cleaned up file ${file}"
-
- // is the parent path empty?
- if (parentFile.isDirectory() && parentFile.listFiles().size() == 0) {
- dirsToDelete << parentFile
+ // run job?
+ if (jobEnabled) {
+ // does the upload path exist?
+ if (uploadPath.exists() && uploadPath.isDirectory()) {
+ // yes, iterate recursively over files
+ uploadPath.eachFileRecurse { file ->
+ if (file.exists()) {
+ if (file.isFile() && currentDate > (file.lastModified() + fileExpiry)) {
+ // file is older than threshold, delete it
+ def parentFile = file.getParentFile()
+
+ if (file.delete()) {
+ log.info "cleaned up file ${file}"
+
+ // is the parent path empty?
+ if (parentFile.isDirectory() && parentFile.listFiles().size() == 0) {
+ dirsToDelete << parentFile
+ }
+ } else {
+ log.error "could not cleanup file ${file}"
}
- } else {
- log.error "could not cleanup file ${file}"
}
}
}
- }
- // add base upload path last
- dirsToDelete << uploadPath
+ // add base upload path last
+ dirsToDelete << uploadPath
- // delete dirs
- dirsToDelete.each { dir ->
- if (dir.isDirectory() && dir.listFiles().size() == 0) {
- if (dir.deleteDir()) {
- log.info "cleaned up directory ${dir}"
- } else {
- log.error "could not cleanup directory ${dir}"
+ // delete dirs
+ dirsToDelete.each { dir ->
+ if (dir.isDirectory() && dir.listFiles().size() == 0) {
+ if (dir.deleteDir()) {
+ log.info "cleaned up directory ${dir}"
+ } else {
+ log.error "could not cleanup directory ${dir}"
+ }
}
}
}

0 comments on commit 83af084

Please sign in to comment.