Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 83af0849e86d7e16ad75c9380e84dea6fc905886 1 parent 2ea4bbb
Jeroen Wesbeek authored
2  UploadrGrailsPlugin.groovy
@@ -15,7 +15,7 @@
15 15 * limitations under the License.
16 16 */
17 17 class UploadrGrailsPlugin {
18   - def version = "0.7.0.1"
  18 + def version = "0.7.1"
19 19 def grailsVersion = "1.3.7 > *"
20 20 def dependsOn = [
21 21 jquery: "1.4 > *",
2  grails-app/conf/Config.groovy
@@ -29,3 +29,5 @@ grails.views.gsp.encoding="UTF-8"
29 29 uploadr.defaultUploadPath="${System.getProperty('user.home')}/Downloads/uploadr"
30 30 // used by the cleanUploadedFilesJob Quartz job (on ci and development)
31 31 uploadr.maxAgeUploadedFile=1000 * 60 * 60 * 4 // 4 hours in milliseconds
  32 +// check if the cleanup job should run or not
  33 +uploadr.cleanupJobEnabled=(grailsApplication.metadata['app.name'] == 'uploadr' && System.getProperty("grails.env") in ["ci","development"])
58 grails-app/jobs/hungry/wombat/CleanUploadedFilesJob.groovy
@@ -14,44 +14,48 @@ class CleanUploadedFilesJob {
14 14 }
15 15
16 16 def execute() {
  17 + def jobEnabled = grailsApplication.config.uploadr.cleanupJobEnabled
17 18 def fileExpiry = grailsApplication.config.uploadr.maxAgeUploadedFile // in milliseconds
18 19 def currentDate = new Date().getTime()
19 20 def uploadPath = new File(grailsApplication.config.uploadr.defaultUploadPath)
20 21 def dirsToDelete= []
21 22
22   - // does the upload path exist?
23   - if (uploadPath.exists() && uploadPath.isDirectory()) {
24   - // yes, iterate recursively over files
25   - uploadPath.eachFileRecurse { file ->
26   - if (file.exists()) {
27   - if (file.isFile() && currentDate > (file.lastModified() + fileExpiry)) {
28   - // file is older than threshold, delete it
29   - def parentFile = file.getParentFile()
30   -
31   - if (file.delete()) {
32   - log.info "cleaned up file ${file}"
33   -
34   - // is the parent path empty?
35   - if (parentFile.isDirectory() && parentFile.listFiles().size() == 0) {
36   - dirsToDelete << parentFile
  23 + // run job?
  24 + if (jobEnabled) {
  25 + // does the upload path exist?
  26 + if (uploadPath.exists() && uploadPath.isDirectory()) {
  27 + // yes, iterate recursively over files
  28 + uploadPath.eachFileRecurse { file ->
  29 + if (file.exists()) {
  30 + if (file.isFile() && currentDate > (file.lastModified() + fileExpiry)) {
  31 + // file is older than threshold, delete it
  32 + def parentFile = file.getParentFile()
  33 +
  34 + if (file.delete()) {
  35 + log.info "cleaned up file ${file}"
  36 +
  37 + // is the parent path empty?
  38 + if (parentFile.isDirectory() && parentFile.listFiles().size() == 0) {
  39 + dirsToDelete << parentFile
  40 + }
  41 + } else {
  42 + log.error "could not cleanup file ${file}"
37 43 }
38   - } else {
39   - log.error "could not cleanup file ${file}"
40 44 }
41 45 }
42 46 }
43   - }
44 47
45   - // add base upload path last
46   - dirsToDelete << uploadPath
  48 + // add base upload path last
  49 + dirsToDelete << uploadPath
47 50
48   - // delete dirs
49   - dirsToDelete.each { dir ->
50   - if (dir.isDirectory() && dir.listFiles().size() == 0) {
51   - if (dir.deleteDir()) {
52   - log.info "cleaned up directory ${dir}"
53   - } else {
54   - log.error "could not cleanup directory ${dir}"
  51 + // delete dirs
  52 + dirsToDelete.each { dir ->
  53 + if (dir.isDirectory() && dir.listFiles().size() == 0) {
  54 + if (dir.deleteDir()) {
  55 + log.info "cleaned up directory ${dir}"
  56 + } else {
  57 + log.error "could not cleanup directory ${dir}"
  58 + }
55 59 }
56 60 }
57 61 }

0 comments on commit 83af084

Please sign in to comment.
Something went wrong with that request. Please try again.