-
Notifications
You must be signed in to change notification settings - Fork 184
Add: Prune reports that match a specific status #311
Conversation
errors << "I don't know that condition. Valid conditionss are: #{known_conditions}"\ | ||
end | ||
else | ||
condition = "!=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this not
instead of !=
This is awesome! A few comments inlined above. |
Hi, thanks a lot for your comments. |
transaction do | ||
old_report_ids = self.reports.where('reports.time < ?', cutoff).pluck(:id) | ||
old_report_ids = self.reports.where("reports.time < \"#{cutoff}\" and reports.status #{condition} \"#{status}\"").pluck(:id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this one, same change as in the other file:
.where("reports.time < ? AND reports.status #{condition} ?", cutoff, status)
Fixed that, too. |
|
||
if condition = ENV['condition'] | ||
unless conditions.has_key?(condition) | ||
errors << "I don't know that condition. Valid conditionss are: #{known_conditions}"\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra 's' on conditions.
The default behavior should be to delete reports of any status older than the given date, but I think the way the queries are written, you must supply a status, otherwise it won't delete anything? |
Cleanup done. The default behavior is just as it has been before. If you don't specify status & condition, it will become: which will match every status in that table. |
Oh, gotcha. I would worry about a performance impact from this; the reports table tends to be huge. The index covering add_index "reports", ["time", "node_id", "status"], :name => "index_reports_on_time_and_node_id_and_status" |
Hm, I'm not really into databases, so I can't tell. |
We could change the default values for status and/or condition to "nil" and build the query in a if-condition f.e.: I don't know if the syntax for the strings is correct, but that could be the way to go. |
@Nold360 hi thanks for the feature! this sounds really great but I notice your source repo has disappeared! if you want to work on this some more I can help |
Hi,
I've added the possibility to prune reports based on their status.
F.e. it's now possible to prune only reports that have the status "unchanged".
Examples:
RAILS_ENV=production bundle exec rake reports:prune unit=mon upto=1 condition=is status=unchanged
RAILS_ENV=production bundle exec rake reports:prune unit=mon upto=1 condition=not status=changed
Since this is the first time I've been codeing ruby, the changes will be most likely not that nice. I hope you like the feature anyway.
Best Regards,
Nold