-
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.
[api] Move ProjectLogRotate to 1 event per job
- Loading branch information
Showing
4 changed files
with
27 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,9 @@ | ||
class ProjectLogRotateJob < ApplicationJob | ||
queue_as :project_log_rotate | ||
|
||
def perform | ||
# Package and Project events | ||
event_types = ["Event::BranchCommand", | ||
"Event::Build", | ||
"Event::CommentForPackage", | ||
"Event::Commit", | ||
"Event::CreatePackage", | ||
"Event::DeletePackage", | ||
"Event::ServiceFail", | ||
"Event::ServiceSuccess", | ||
"Event::UndeletePackage", | ||
"Event::UpdatePackage", | ||
"Event::Upload", | ||
"Event::VersionChange", | ||
"Event::CommentForProject", | ||
"Event::CreateProject", | ||
"Event::DeleteProject", | ||
"Event::UndeleteProject", | ||
"Event::UpdateProjectConfig", | ||
"Event::UpdateProject"] | ||
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 (but this time, only those 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 | ||
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 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