Commit c4d9055d authored by Gabriel Mazetto's avatar Gabriel Mazetto

Improve Geo Framework code documentation

Added missing YARD tags and method signature information on several
parts of Geo Framework
parent 26762b65
...@@ -11,9 +11,6 @@ module Geo ...@@ -11,9 +11,6 @@ module Geo
event :created event :created
end end
class_methods do
end
def handle_after_create_commit def handle_after_create_commit
publish(:created, **created_params) publish(:created, **created_params)
...@@ -53,6 +50,10 @@ module Geo ...@@ -53,6 +50,10 @@ module Geo
private private
# Update checksum on main database
#
# @param [String] checksum value generated by the checksum routine
# @param [String] failure (optional) stacktrace from failed execution
def update_verification_state!(checksum: nil, failure: nil) def update_verification_state!(checksum: nil, failure: nil)
retry_at, retry_count = calculate_next_retry_attempt if failure.present? retry_at, retry_count = calculate_next_retry_attempt if failure.present?
......
...@@ -15,6 +15,9 @@ module Gitlab ...@@ -15,6 +15,9 @@ module Gitlab
end end
class_methods do class_methods do
# Associate current model with specified replicator
#
# @param [Gitlab::Geo::Replicator] klass
def with_replicator(klass) def with_replicator(klass)
raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator raise ArgumentError, 'Must be a class inheriting from Gitlab::Geo::Replicator' unless klass < ::Gitlab::Geo::Replicator
...@@ -28,11 +31,13 @@ module Gitlab ...@@ -28,11 +31,13 @@ module Gitlab
# Geo Replicator # Geo Replicator
# #
# @abstract
# @return [Gitlab::Geo::Replicator] # @return [Gitlab::Geo::Replicator]
def replicator def replicator
raise NotImplementedError, 'There is no Replicator defined for this model' raise NotImplementedError, 'There is no Replicator defined for this model'
end end
# Clear model verification checksum and force recalculation
def calculate_checksum! def calculate_checksum!
self.verification_checksum = nil self.verification_checksum = nil
...@@ -41,10 +46,20 @@ module Gitlab ...@@ -41,10 +46,20 @@ module Gitlab
self.verification_checksum = self.class.hexdigest(file.path) self.verification_checksum = self.class.hexdigest(file.path)
end end
# Checks whether model needs checksum to be performed
#
# Conditions:
# - No checksum is present
# - It's capable of generating a checksum of itself
#
# @return [Boolean]
def needs_checksum? def needs_checksum?
verification_checksum.nil? && checksummable? verification_checksum.nil? && checksummable?
end end
# Return whether its capable of generating a checksum of itself
#
# @return [Boolean] whether it can generate a checksum
def checksummable? def checksummable?
local? && file_exist? local? && file_exist?
end end
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
module Gitlab module Gitlab
module Geo module Geo
module Replication module Replication
# Handles retrieval of a blob to be returned via the Geo API request
#
class BlobRetriever < BaseRetriever class BlobRetriever < BaseRetriever
attr_reader :replicator, :checksum attr_reader :replicator, :checksum
......
...@@ -2,9 +2,19 @@ ...@@ -2,9 +2,19 @@
module Gitlab module Gitlab
module Geo module Geo
# Geo Replicators are objects that knows to to replicator a replicable resource
#
# A replicator is responsible for:
# - firing events (producer)
# - consuming events (consumer)
#
# Each replicator is tied to a specific replicable resource
class Replicator class Replicator
include ::Gitlab::Geo::LogHelpers include ::Gitlab::Geo::LogHelpers
attr_reader :model_record_id
delegate :model, to: :class
# Declare supported event # Declare supported event
# #
# @example Declaring support for :update and :delete events # @example Declaring support for :update and :delete events
...@@ -29,22 +39,34 @@ module Gitlab ...@@ -29,22 +39,34 @@ module Gitlab
# Check if the replicator supports a specific event # Check if the replicator supports a specific event
# #
# @param [Boolean] event_name # @param [Symbol] event_name
# @return [Boolean] whether event support was registered in the replicator
def self.event_supported?(event_name) def self.event_supported?(event_name)
@events.include?(event_name.to_sym) @events.include?(event_name.to_sym)
end end
# Return the name of the replicator # Return the name of the replicator
# #
# @return [String] name # This can be used to retrieve the replicator class again
# by using the `.for_replicable_name` method
#
# @see .for_replicable_name
# @return [String] slug that identifies this replicator
def self.replicable_name def self.replicable_name
self.name.demodulize.sub('Replicator', '').underscore self.name.demodulize.sub('Replicator', '').underscore
end end
# Return the registry related to the replicable resource
#
# @return [Class<Geo::BaseRegistry>] registry class
def self.registry_class def self.registry_class
const_get("::Geo::#{replicable_name.camelize}Registry", false) const_get("::Geo::#{replicable_name.camelize}Registry", false)
end end
# Given a `replicable_name`, return the corresponding replicator
#
# @param [String] replicable_name the replicable slug
# @return [Class<Geo::Replicator>] replicator implementation
def self.for_replicable_name(replicable_name) def self.for_replicable_name(replicable_name)
replicator_class_name = "::Geo::#{replicable_name.camelize}Replicator" replicator_class_name = "::Geo::#{replicable_name.camelize}Replicator"
...@@ -67,15 +89,17 @@ module Gitlab ...@@ -67,15 +89,17 @@ module Gitlab
model.count model.count
end end
attr_reader :model_record_id # @param [ActiveRecord::Base] model_record
# @param [Integer] model_record_id
delegate :model, to: :class
def initialize(model_record: nil, model_record_id: nil) def initialize(model_record: nil, model_record_id: nil)
@model_record = model_record @model_record = model_record
@model_record_id = model_record_id @model_record_id = model_record_id
end end
# Instance of the replicable model
#
# @return [ActiveRecord::Base, nil]
# @raise ActiveRecord::RecordNotFound when a model with specified model_record_id can't be found
def model_record def model_record
if defined?(@model_record) && @model_record if defined?(@model_record) && @model_record
return @model_record return @model_record
...@@ -86,6 +110,10 @@ module Gitlab ...@@ -86,6 +110,10 @@ module Gitlab
end end
end end
# Publish an event with its related data
#
# @param [Symbol] event_name
# @param [Hash] event_data
def publish(event_name, **event_data) def publish(event_name, **event_data)
return unless Feature.enabled?(:geo_self_service_framework) return unless Feature.enabled?(:geo_self_service_framework)
...@@ -119,18 +147,30 @@ module Gitlab ...@@ -119,18 +147,30 @@ module Gitlab
send(consume_method, **params) # rubocop:disable GitlabSecurity/PublicSend send(consume_method, **params) # rubocop:disable GitlabSecurity/PublicSend
end end
# Return the name of the replicator
#
# @return [String] slug that identifies this replicator
def replicable_name def replicable_name
self.class.replicable_name self.class.replicable_name
end end
# Return the registry related to the replicable resource
#
# @return [Class<Geo::BaseRegistry>] registry class
def registry_class def registry_class
self.class.registry_class self.class.registry_class
end end
# Return registry instance scoped to current model
#
# @return [Geo::BaseRegistry] registry instance
def registry def registry
registry_class.for_model_record_id(model_record.id) registry_class.for_model_record_id(model_record.id)
end end
# Checksum value from the main database
#
# @abstract
def primary_checksum def primary_checksum
nil nil
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment