-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4197 from Ana06/project_log_rotate
[api] Move ProjectLogRotate to 1 event per job
- Loading branch information
Showing
10 changed files
with
77 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateProjectLogEntryJob < ApplicationJob | ||
queue_as :project_log_rotate | ||
|
||
def perform(event_id) | ||
event = Event::Base.find(event_id) | ||
entry = ProjectLogEntry.create_from(event) | ||
event.update_attributes(project_logged: true) if entry.persisted? | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
module Event | ||
PROJECT_CLASSES = ["Event::CommentForProject", | ||
"Event::CreateProject", | ||
"Event::DeleteProject", | ||
"Event::UndeleteProject", | ||
"Event::UpdateProjectConfig", | ||
"Event::UpdateProject"].freeze | ||
PACKAGE_CLASSES = ["Event::BranchCommand", | ||
"Event::Build", | ||
"Event::CommentForPackage", | ||
"Event::Commit", | ||
"Event::CreatePackage", | ||
"Event::DeletePackage", | ||
"Event::ServiceFail", | ||
"Event::ServiceSuccess", | ||
"Event::UndeletePackage", | ||
"Event::UpdatePackage", | ||
"Event::Upload", | ||
"Event::VersionChange"].freeze | ||
end |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
desc 'Run project log rotate job manually' | ||
task :project_log_rotate_manually do | ||
event_types = Event::PROJECT_CLASSES | Event::PACKAGE_CLASSES | ||
oldest_date = 10.days.ago | ||
|
||
# First, skip old events and mark them all as "logged" (even those that | ||
# don't belong to the event_classes) | ||
Event::Base.where(project_logged: false).where(["created_at < ?", oldest_date]).update_all(project_logged: true) | ||
|
||
# Create log entries based on the events in event_classes | ||
Event::Base.where(project_logged: false, eventtype: event_types).find_in_batches(batch_size: 10000) do |events_batch| | ||
events_batch.each do |event| | ||
entry = ProjectLogEntry.create_from(event) | ||
event.update_attributes(project_logged: true) if entry.persisted? | ||
end | ||
end | ||
|
||
# Clean up old entries | ||
ProjectLogEntry.clean_older_than oldest_date | ||
end |
This file contains 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
This file contains 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