Skip to content

Commit

Permalink
fix cleanup for good
Browse files Browse the repository at this point in the history
  • Loading branch information
peh committed Mar 27, 2017
1 parent 544a68f commit 870a452
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
5 changes: 2 additions & 3 deletions grails-app/assets/javascripts/app/app.js
Expand Up @@ -16,8 +16,7 @@ const querystring = require('querystring');
export default class App {
constructor() {

this.baseUrl = window.upstream;
this.showRefind = LocalStore.get('errbuddy.refind.show') === 'true';
this.baseUrl = window.backend;
this.action = null;
this.paused = false;

Expand All @@ -28,7 +27,7 @@ export default class App {
showRefind: false
};

this._me = null
this._me = null;
this.emitter = new EventEmitter();
this.emitter.setMaxListeners(0);

Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/errbuddy/EntryGroup.groovy
Expand Up @@ -42,6 +42,7 @@ class EntryGroup implements HasJsonBody {
issueUrl nullable: true
resolveDate nullable: true
resolvedBy nullable: true
latest nullable: true
}

def beforeValidate() {
Expand Down
4 changes: 2 additions & 2 deletions grails-app/jobs/errbuddy/EntryCleanupJob.groovy
Expand Up @@ -15,7 +15,7 @@ class EntryCleanupJob {
args: [0]
}

def dataRetentionService
EntryCleanupService entryCleanupService
GrailsApplication grailsApplication

def perform(long id = 0) {
Expand All @@ -39,7 +39,7 @@ class EntryCleanupJob {
app.clearUntil = until
app.save()
}
dataRetentionService.handleDataRetentionForApplication(app)
entryCleanupService.handleEntryCleanupForApplication(app)
}

}
@@ -0,0 +1,6 @@
databaseChangeLog = {

changeSet(author: "peh (generated)", id: "1490609684437-1") {
dropNotNullConstraint(columnDataType: "bigint", columnName: "latest_id", tableName: "entry_group")
}
}
1 change: 1 addition & 0 deletions grails-app/migrations/changelog.groovy
Expand Up @@ -5,4 +5,5 @@ databaseChangeLog = {
include file: '20170203_add_identifier_index.groovy'
include file: '20172503_drop_monitoring.groovy'
include file: '20172603_add_date_created_index.groovy'
include file: '20172703_remove_latest_not_null_constraint.groovy'
}
27 changes: 0 additions & 27 deletions grails-app/services/errbuddy/DataRetentionService.groovy

This file was deleted.

32 changes: 32 additions & 0 deletions grails-app/services/errbuddy/EntryCleanupService.groovy
@@ -0,0 +1,32 @@
package errbuddy

import grails.transaction.Transactional

@Transactional
class EntryCleanupService {

def jesqueService

void handleEntryCleanupForApplication(App app) {
int max = 10000
def entries = Entry.createCriteria().list([max: max]) {
entryGroup {
eq('app', app)
}
projections {
property('id')
property('dateCreated')
}
} as List

def toDelete = entries.findAll { it[1].isBefore(app.clearUntil) }.collect { it[0] }.flatten()
if (!toDelete) {
return
}

log.info "deleting ${toDelete.size()} entries for $app.name"
toDelete.each { long entryId ->
jesqueService.enqueue(EntryDeleteJob.queueName, EntryDeleteJob, [entryId, true])
}
}
}
4 changes: 2 additions & 2 deletions grails-app/services/errbuddy/EntryService.groovy
Expand Up @@ -169,8 +169,8 @@ class EntryService {
}

if (doCheckLatest) {
EntryGroup.findByLatest(entry).each {
it.latest = null
EntryGroup.findAllByLatest(entry).each { // this should really never be more then one, but we saw it happen so lets go for each ...
it.latest = Entry.findByEntryGroupAndIdNotEqual(it, id, [sort: 'id', order: 'desc'])
it.save()
}
}
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/page/app.gsp
Expand Up @@ -8,7 +8,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="${asset.assetPath(src: "favicon.ico")}" type="image/x-icon">
<script type="text/javascript">
window.upstream = '${System.getProperty('grails.upstream.url') ?: (grailsApplication.config.grails.serverURL ?: 'http://localhost:9000')}';
window.backend = '${System.getProperty('errbuddy.backend.url') ?: (grailsApplication.config.grails.serverURL ?: 'http://localhost:9000')}';
</script>
<babel:webpack src="app.es6"/>
</head>
Expand Down

0 comments on commit 870a452

Please sign in to comment.