discourse/migrations/lib/converters/base/progress_stats.rb
Gerhard Schlager 7c3a29c9d6
DEV: Add converter framework for migrations-tooling (#28540)
* Updates GitHub Actions
* Switches from `bundler/inline` to an optional group in the `Gemfile` because the previous solution didn't work well with rspec
* Adds the converter framework and tests
* Allows loading private converters (see README)
* Switches from multiple CLI tools to a single CLI
* Makes DB connections reusable and adds a new abstraction for the `IntermediateDB`
* `IntermediateDB` acts as an interface for IPC calls when a converter steps runs in parallel (forks). Only the main process writes to the DB.
* Includes a simple example implementation of a converter for now.
2024-09-09 17:14:39 +02:00

48 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Migrations::Converters::Base
class ProgressStats
attr_accessor :progress, :warning_count, :error_count
def initialize
reset!
end
def reset!
@progress = 1
@warning_count = 0
@error_count = 0
end
def log_info(message, details: nil)
log(::Migrations::Database::IntermediateDB::LogEntry::INFO, message, details:)
end
def log_warning(message, exception: nil, details: nil)
@warning_count += 1
log(::Migrations::Database::IntermediateDB::LogEntry::WARNING, message, exception:, details:)
end
def log_error(message, exception: nil, details: nil)
@error_count += 1
log(::Migrations::Database::IntermediateDB::LogEntry::ERROR, message, exception:, details:)
end
def ==(other)
other.is_a?(ProgressStats) && progress == other.progress &&
warning_count == other.warning_count && error_count == other.error_count
end
private
def log(type, message, exception: nil, details: nil)
::Migrations::Database::IntermediateDB::LogEntry.create!(
type:,
message:,
exception:,
details:,
)
end
end
end