Last active
August 29, 2015 14:04
-
-
Save sizovs/e7fe8f364bbb3bebfe97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map dropConditions = [ | |
new_do_stuff_toggled : { cfg("new_do_stuff.enabled") == "true" }, | |
marketing_campaign_finished : { timeCame "09/04/2014" } | |
] | |
def timeCame(String date) { | |
def today = new Date() | |
def expirationDate = new Date().parse('dd/MM/yyyy', date) | |
today.after expirationDate | |
} | |
def cfg(key) { | |
def uri = "http://production.configuration/$key".toURL() | |
uri.getText(connectTimeout: 2000, readTimeout: 3000) | |
} | |
new File('.').eachFileRecurse(groovy.io.FileType.FILES) { | |
if (it.name.endsWith(".java")) { | |
def hits = it.text =~ /\/\/\s*DROP\s*\[\s*(.*)\s*\]\n/ | |
hits.each { match, key -> | |
def dropConditionForAGivenKey = dropConditions[(key)] | |
if (!dropConditionForAGivenKey) { | |
println("<!> Cannot find drop conditions for key '$key'") | |
return | |
} | |
try { | |
def canBeDropped = dropConditionForAGivenKey() | |
if (canBeDropped) { | |
println "--- Drop condition for key '$key' is satisfied. Time to cleanup $it.name" | |
} | |
} catch (IOException ioException) { | |
println("<!> Cannot evaluate drop condition for key '$key' due to: $ioException") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment