Skip to content

Commit

Permalink
Merge pull request #6508 from hennevogel/feature/project-log-entry-cl…
Browse files Browse the repository at this point in the history
…eanup-job

Project log entry cleanup job
  • Loading branch information
hennevogel committed Dec 7, 2018
2 parents 800bdc2 + 43f24cd commit 5287d4f
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/projects/pulse_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def update_pulse
end

pulse = @project.project_log_entries.where(datetime: range).order(datetime: :asc)
@builds = pulse.where(event_type: [:build_fail, :build_success])
@builds = pulse.where(event_type: [:build_fail, :build_success]).where(datetime: 24.hours.ago..Time.zone.now)
@new_packages = pulse.where(event_type: :create_package)
@deleted_packages = pulse.where(event_type: :delete_package)
@branches = pulse.where(event_type: :branch_command)
Expand Down
7 changes: 7 additions & 0 deletions src/api/app/jobs/cleanup_project_log_entries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class CleanupProjectLogEntries < ApplicationJob
queue_as :project_log_rotate

def perform
ProjectLogEntries.cleanup
end
end
5 changes: 2 additions & 3 deletions src/api/app/models/project_log_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ def self.create_from(payload, created_at, event_model_name)
entry
end

# Delete old entries
def self.clean_older_than(date)
where('datetime < ?', date).delete_all
def self.cleanup
where(event_type: [:build_fail, :build_success]).where('datetime < ?', Time.zone.yesterday).delete_all
end

# Human readable message, based in the event class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

%h5#pulse-builds
Builds
%small
(in the last 24 hours)
%hr
%ul.list-unstyled
- builds.each do |log_entry|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
been
= link_to('#pulse-builds') do
= builds.values.sum
builds
builds in the last 24 hours
of which
%b.text-danger
= builds['build_fail']
Expand Down
4 changes: 4 additions & 0 deletions src/api/config/clock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ module Clockwork
CleanupEvents.perform_later
end

every(1.day, 'clean old project log entries', at: '02:30') do
CleanupProjectLogEntries.perform_later
end

every(1.day, 'create cleanup requests', at: '06:00') do
User.current = User.get_default_admin
ProjectCreateAutoCleanupRequests.perform_later
Expand Down
6 changes: 0 additions & 6 deletions src/api/test/models/project_log_entry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,4 @@ class ProjectLogEntryTest < ActiveSupport::TestCase
assert_nil entry.bs_request
assert_equal({ 'repository' => '10.2', 'arch' => 'i586', 'rev' => '5' }, entry.additional_info)
end

test '#clean_older_than' do
count = ProjectLogEntry.count
ProjectLogEntry.clean_older_than(Date.parse('2013-08-09'))
assert_equal count - 1, ProjectLogEntry.count
end
end

0 comments on commit 5287d4f

Please sign in to comment.