Skip to content

Commit

Permalink
fix data retention job
Browse files Browse the repository at this point in the history
  • Loading branch information
peh committed Mar 26, 2017
1 parent cc051c4 commit 682d94c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ dependencies {
compile "org.grails.plugins:errbuddy:2.1.0"
compile "com.uberall.plugins:uber-doc:2.0.4"
compile 'org.grails.plugins:elasticsearch:1.0.0.2'
compile 'org.grails.plugins:grails-jesque-admin:0.1.5'
compile 'org.grails.plugins:jesque-admin:0.6.5'
compile 'org.grails.plugins:jesque:1.2.1-UBERALL'

assets 'net.errbuddy.plugins:babel-asset-pipeline:2.1.0'
Expand Down
1 change: 1 addition & 0 deletions default-config.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ errbuddy {
maximumMax = 100
supportedLanguages = ['en']
defaultLanguage = 'en'
retentionDays = 90
}

elasticSearch {
Expand Down
24 changes: 20 additions & 4 deletions grails-app/jobs/errbuddy/DataRetentionJob.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package errbuddy

import grails.core.GrailsApplication
import org.joda.time.DateTime

class DataRetentionJob {

static queueName = "put"
Expand All @@ -13,17 +16,30 @@ class DataRetentionJob {
}

def dataRetentionService
GrailsApplication grailsApplication

def perform(long id = 0) {
if (id) {
dataRetentionService.handleDataRetentionForApplication(id)
App app = App.get(id)
if (app) {
handle(app)
}
} else {
App.createCriteria().list {
eq('enabled', true)
projections { property('id') }
}.each { long appId ->
dataRetentionService.handleDataRetentionForApplication(appId)
}.each { App app ->
handle(app)
}
}
}

void handle(App app) {
DateTime until = DateTime.now().minusDays(grailsApplication.config.errbuddy.retentionDays ?: 90)
if (!app.clearUntil || app.clearUntil.isBefore(until)) {
app.clearUntil = until
app.save()
}
dataRetentionService.handleDataRetentionForApplication(app)
}

}
5 changes: 1 addition & 4 deletions grails-app/services/errbuddy/DataRetentionService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ class DataRetentionService {

def jesqueService

void handleDataRetentionForApplication(long id) {
def app = App.read(id)
if (!app) return

void handleDataRetentionForApplication(App app) {
int max = 10000
def entries = Entry.createCriteria().list([max: max]) {
entryGroup {
Expand Down

0 comments on commit 682d94c

Please sign in to comment.