Skip to content

Commit

Permalink
Merge pull request #4191 from Ana06/refactor_event
Browse files Browse the repository at this point in the history
Refactor Event module
  • Loading branch information
hennevogel committed Dec 7, 2017
2 parents 2e615f4 + 10a9af1 commit 4e6efd8
Show file tree
Hide file tree
Showing 49 changed files with 1,277 additions and 758 deletions.
54 changes: 26 additions & 28 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-10-31 11:22:54 +0000 using RuboCop version 0.51.0.
# on 2017-12-04 09:56:31 +0000 using RuboCop version 0.51.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -62,7 +62,7 @@ Layout/EmptyLinesAroundBeginBody:
Exclude:
- 'src/api/app/controllers/webui/patchinfo_controller.rb'

# Offense count: 34
# Offense count: 35
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Expand Down Expand Up @@ -123,14 +123,13 @@ Layout/IndentHeredoc:
- 'src/api/test/unit/bs_request_test.rb'
- 'src/api/test/unit/project_test.rb'

# Offense count: 11
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: normal, rails
Layout/IndentationConsistency:
Exclude:
- 'src/api/app/controllers/webui/configuration_controller.rb'
- 'src/api/lib/activexml/node.rb'
- 'src/api/test/functional/statistics_controller_test.rb'
- 'src/api/test/unit/ichain_notifier_test.rb'

Expand Down Expand Up @@ -179,7 +178,7 @@ Layout/MultilineHashBraceLayout:
- 'src/api/test/functional/request_controller_test.rb'
- 'src/api/test/functional/source_controller_test.rb'

# Offense count: 67
# Offense count: 66
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Expand Down Expand Up @@ -229,7 +228,7 @@ Layout/SpaceInLambdaLiteral:
- 'src/api/app/models/package_issue.rb'
- 'src/api/config/routes.rb'

# Offense count: 122
# Offense count: 125
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
Expand All @@ -243,7 +242,7 @@ Layout/SpaceInsideBrackets:
Exclude:
- 'src/api/app/views/result/packageresult.xml.builder'

# Offense count: 1326
# Offense count: 1325
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
Expand Down Expand Up @@ -271,15 +270,14 @@ Layout/SpaceInsideStringInterpolation:
- 'src/api/app/models/user_ldap_strategy.rb'
- 'src/api/lib/xpath_engine.rb'

# Offense count: 6
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Layout/Tab:
Exclude:
- 'src/api/app/views/webui/feeds/commits.atom.builder'
- 'src/api/lib/activexml/node.rb'

# Offense count: 22
# Offense count: 24
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: final_newline, final_blank_line
Expand Down Expand Up @@ -383,11 +381,11 @@ Lint/UnneededDisable:
Lint/UriEscapeUnescape:
Enabled: false

# Offense count: 894
# Offense count: 899
Metrics/AbcSize:
Max: 248

# Offense count: 406
# Offense count: 411
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 988
Expand All @@ -397,16 +395,16 @@ Metrics/BlockLength:
Metrics/BlockNesting:
Max: 6

# Offense count: 88
# Offense count: 91
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 1157

# Offense count: 243
# Offense count: 244
Metrics/CyclomaticComplexity:
Max: 55

# Offense count: 955
# Offense count: 958
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 264
Expand Down Expand Up @@ -596,7 +594,7 @@ Rails/FindEach:
- 'src/api/app/models/project.rb'
- 'src/api/app/models/user.rb'

# Offense count: 13
# Offense count: 12
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasAndBelongsToMany:
Expand Down Expand Up @@ -693,7 +691,7 @@ Style/BlockDelimiters:
Style/BracesAroundHashParameters:
Enabled: false

# Offense count: 82
# Offense count: 83
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Expand Down Expand Up @@ -736,18 +734,17 @@ Style/CommentAnnotation:
- 'src/api/test/functional/build_controller_test.rb'
- 'src/api/test/functional/request_controller_test.rb'

# Offense count: 10
# Offense count: 8
Style/CommentedKeyword:
Exclude:
- 'src/api/app/helpers/webui/webui_helper.rb'
- 'src/api/app/models/bs_request_action.rb'
- 'src/api/lib/activexml/node.rb'
- 'src/api/test/functional/source_controller_test.rb'
- 'src/api/test/unit/project_remove_test.rb'
- 'src/api/test/unit/user_ldap_strategy_test.rb'
- 'src/api/test/unit/user_test.rb'

# Offense count: 93
# Offense count: 94
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Expand All @@ -770,7 +767,7 @@ Style/Dir:
Exclude:
- 'src/api/script/start_test_backend'

# Offense count: 625
# Offense count: 634
Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -828,7 +825,7 @@ Style/For:
- 'src/api/test/unit/debug_flag_test.rb'
- 'src/api/test/unit/publish_flag_test.rb'

# Offense count: 15
# Offense count: 9
# Configuration parameters: SupportedStyles.
# SupportedStyles: annotated, template
Style/FormatStringToken:
Expand Down Expand Up @@ -881,9 +878,10 @@ Style/MethodMissing:
- 'src/api/app/models/configuration.rb'
- 'src/api/lib/opensuse/permission.rb'

# Offense count: 2
# Offense count: 3
Style/MixinUsage:
Exclude:
- 'src/api/app/controllers/request_controller.rb'
- 'src/api/app/controllers/source_controller.rb'
- 'src/api/app/helpers/maintenance_helper.rb'

Expand All @@ -910,7 +908,7 @@ Style/NegatedWhile:
- 'src/api/app/models/issue_tracker.rb'
- 'src/api/lib/xpath_engine.rb'

# Offense count: 31
# Offense count: 30
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
# SupportedStyles: skip_modifier_ifs, always
Expand Down Expand Up @@ -997,7 +995,7 @@ Style/RedundantBegin:
- 'src/api/app/controllers/webui/patchinfo_controller.rb'
- 'src/api/app/controllers/webui/project_controller.rb'
- 'src/api/app/models/bs_request_action.rb'
- 'src/api/app/models/event/build.rb'
- 'src/api/app/models/event/build_fail.rb'
- 'src/api/app/models/package.rb'
- 'src/api/config/routes.rb'
- 'src/api/db/migrate/20140721112346_delayed_job_indexes.rb'
Expand Down Expand Up @@ -1056,7 +1054,7 @@ Style/StderrPuts:
Exclude:
- 'src/api/test/functional/webui/spider_test.rb'

# Offense count: 9308
# Offense count: 9303
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -1077,7 +1075,7 @@ Style/StringLiteralsInInterpolation:
- 'src/api/lib/tasks/cleanup_sessions.rake'
- 'src/api/lib/tasks/databases.rake'

# Offense count: 271
# Offense count: 272
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinSize, SupportedStyles.
# SupportedStyles: percent, brackets
Expand All @@ -1093,7 +1091,7 @@ Style/TrivialAccessors:
- 'src/api/lib/activexml/node.rb'
- 'src/api/test/test_helper.rb'

# Offense count: 129
# Offense count: 128
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Expand Down
2 changes: 0 additions & 2 deletions src/api/app/controllers/request_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require_dependency 'event/all'

include MaintenanceHelper

class RequestController < ApplicationController
Expand Down
1 change: 0 additions & 1 deletion src/api/app/controllers/source_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
include ValidationHelper

require 'builder/xchar'
require 'event'

class SourceController < ApplicationController
class IllegalRequest < APIException
Expand Down
2 changes: 0 additions & 2 deletions src/api/app/controllers/webui/user_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'event'

class Webui::UserController < Webui::WebuiController
before_action :check_display_user, only: [:show, :edit, :list_my, :delete, :confirm, :admin, :lock]
before_action :require_login, only: [:edit, :save, :index]
Expand Down
21 changes: 19 additions & 2 deletions src/api/app/jobs/project_log_rotate_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ class ProjectLogRotateJob < ApplicationJob
queue_as :project_log_rotate

def perform
event_classes = [Event::Package, Event::Project]
event_types = event_classes.flat_map(&:descendants).map(&:name)
# 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
Expand Down
1 change: 0 additions & 1 deletion src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require 'xmlhash'
require 'event'

include MaintenanceHelper

Expand Down
1 change: 0 additions & 1 deletion src/api/app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'event'
require 'set'

class Comment < ApplicationRecord
Expand Down
3 changes: 2 additions & 1 deletion src/api/app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require_relative 'event/all'
module Event
end
10 changes: 0 additions & 10 deletions src/api/app/models/event/all.rb

This file was deleted.

36 changes: 36 additions & 0 deletions src/api/app/models/event/branch_command.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module Event
class BranchCommand < Base
self.description = 'Package was branched'
payload_keys :project, :package, :sender, :targetproject, :targetpackage, :user
after_create_commit :send_to_bus

def self.message_bus_routing_key
"#{Configuration.amqp_namespace}.package.branch"
end

def subject
"Package Branched: #{payload['project']}/#{payload['package']} => #{payload['targetproject']}/#{payload['targetpackage']}"
end
end
end

# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# eventtype :string(255) not null, indexed
# payload :text(65535)
# created_at :datetime indexed
# updated_at :datetime
# project_logged :boolean default(FALSE), indexed
# undone_jobs :integer default(0)
# mails_sent :boolean default(FALSE), indexed
#
# Indexes
#
# index_events_on_created_at (created_at)
# index_events_on_eventtype (eventtype)
# index_events_on_mails_sent (mails_sent)
# index_events_on_project_logged (project_logged)
#
Loading

0 comments on commit 4e6efd8

Please sign in to comment.