Skip to content

Commit

Permalink
feat(matrix): refresh head matrix asynchronously to speed up pact pub…
Browse files Browse the repository at this point in the history
…lishing and tagging
  • Loading branch information
bethesque committed Feb 6, 2018
1 parent ecfca29 commit 989e6e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
16 changes: 16 additions & 0 deletions lib/pact_broker/matrix/refresh_head_matrix_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'sucker_punch'
require 'pact_broker/matrix/head_row'

module PactBroker
module Matrix
class RefreshHeadMatrixJob

include SuckerPunch::Job
include PactBroker::Logging

def perform params
PactBroker::Matrix::HeadRow.refresh(params[:params])
end
end
end
end
10 changes: 7 additions & 3 deletions lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
require 'pact_broker/matrix/row'
require 'pact_broker/matrix/latest_row'
require 'pact_broker/matrix/head_row'
require 'pact_broker/matrix/refresh_head_matrix_job'
require 'pact_broker/error'


module PactBroker
module Matrix

Expand All @@ -23,7 +25,7 @@ class Repository

def refresh params
PactBroker::Matrix::Row.refresh(params)
PactBroker::Matrix::HeadRow.refresh(params)
RefreshHeadMatrixJob.perform_in(1, params: params)
end

# Return the latest matrix row (pact/verification) for each consumer_version_number/provider_version_number
Expand Down Expand Up @@ -128,11 +130,13 @@ def look_up_versions_for_latest_and_tag(selectors, options)
end
end.collect do | selector |
if selector[:pacticipant_name]
selector[:pacticipant_id] = PactBroker::Domain::Pacticipant.find(name: selector[:pacticipant_name]).id
pacticipant = PactBroker::Domain::Pacticipant.find(name: selector[:pacticipant_name])
selector[:pacticipant_id] = pacticipant ? pacticipant.id : nil
end

if selector[:pacticipant_name] && selector[:pacticipant_version_number]
selector[:pacticipant_version_id] = version_repository.find_by_pacticipant_name_and_number(selector[:pacticipant_name], selector[:pacticipant_version_number]).id
version = version_repository.find_by_pacticipant_name_and_number(selector[:pacticipant_name], selector[:pacticipant_version_number])
selector[:pacticipant_version_id] = version ? version.id : nil
end

if selector[:pacticipant_version_number].nil?
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/matrix/row.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'pact_broker/repositories/helpers'
require 'pact_broker/webhooks/latest_triggered_webhook'
require 'pact_broker/tags/tag_with_latest_flag'
require 'pact_broker/logging'

module PactBroker
module Matrix
Expand All @@ -16,8 +17,11 @@ class Row < Sequel::Model(:materialized_matrix)

dataset_module do
include PactBroker::Repositories::Helpers
include PactBroker::Logging

def refresh params
logger.debug("Refreshing #{model.table_name} for #{params}")

source_view_name = model.table_name.to_s.gsub('materialized_', '').to_sym
if params[:consumer_name] || params[:provider_name]
criteria = {}
Expand Down

0 comments on commit 989e6e3

Please sign in to comment.