Skip to content

Instantly share code, notes, and snippets.

@deanproctor
Created July 31, 2020 18:22
Show Gist options
  • Save deanproctor/8d1f9b6344d6c91f398bdc5c540e7acb to your computer and use it in GitHub Desktop.
Save deanproctor/8d1f9b6344d6c91f398bdc5c540e7acb to your computer and use it in GitHub Desktop.
Groovy script to set the roll attribute once per hour per table
import groovy.time.TimeCategory
if (!state.containsKey('lastRoll')) {
state << [lastRoll: [:]]
}
def setRollFlag(String tableName) {
if (!state.lastRoll.containsKey(tableName)) {
state.lastRoll[tableName] = new Date()
}
use (TimeCategory) {
if (state.lastRoll[tableName] < 1.hour.ago) {
state.lastRoll[tableName] = new Date()
return true
log.info("script sets roll flag for measurement")
}
return false
}
}
for (record in records) {
try {
if(setRollFlag(record.attributes['jdbc.tables'])) {
record.attributes['roll'] = 'yes'
}
output.write(record)
} catch (e) {
// Write a record to the error pipeline
log.error(e.toString(), e)
error.write(record, e.toString())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment