mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Remove user_id and points_count parameters from Metrics::Archives::Operation and related calls.
This commit is contained in:
parent
f4aba0991c
commit
670d2e1df7
7 changed files with 26 additions and 36 deletions
|
|
@ -3,11 +3,9 @@
|
|||
class Metrics::Archives::Operation
|
||||
OPERATIONS = %w[archive verify clear restore].freeze
|
||||
|
||||
def initialize(operation:, status:, user_id: nil, points_count: 0)
|
||||
def initialize(operation:, status:)
|
||||
@operation = operation
|
||||
@status = status # 'success' or 'failure'
|
||||
@user_id = user_id
|
||||
@points_count = points_count
|
||||
@status = status # 'success' or 'failure'
|
||||
end
|
||||
|
||||
def call
|
||||
|
|
|
|||
|
|
@ -26,13 +26,10 @@ module Points
|
|||
end
|
||||
|
||||
def archive_specific_month(user_id, year, month)
|
||||
month_data = {
|
||||
'user_id' => user_id,
|
||||
'year' => year,
|
||||
'month' => month
|
||||
}
|
||||
|
||||
process_month(month_data)
|
||||
# Direct call without error handling - allows errors to propagate
|
||||
# This is intended for use in tests and manual operations where
|
||||
# we want to know immediately if something went wrong
|
||||
archive_month(user_id, year, month)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -83,8 +80,7 @@ module Points
|
|||
# Report successful archive operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'archive',
|
||||
status: 'success',
|
||||
user_id: user_id
|
||||
status: 'success'
|
||||
).call
|
||||
|
||||
true
|
||||
|
|
@ -99,8 +95,7 @@ module Points
|
|||
# Report failed archive operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'archive',
|
||||
status: 'failure',
|
||||
user_id: user_id
|
||||
status: 'failure'
|
||||
).call
|
||||
end
|
||||
|
||||
|
|
@ -117,7 +112,7 @@ module Points
|
|||
verification_result = verify_archive_immediately(archive, point_ids)
|
||||
unless verification_result[:success]
|
||||
Rails.logger.error("Immediate verification failed: #{verification_result[:error]}")
|
||||
archive.destroy # Cleanup failed archive
|
||||
archive.destroy # Cleanup failed archive
|
||||
raise StandardError, "Archive verification failed: #{verification_result[:error]}"
|
||||
end
|
||||
|
||||
|
|
@ -206,7 +201,7 @@ module Points
|
|||
year: year,
|
||||
month: month,
|
||||
chunk_number: chunk_number,
|
||||
point_count: actual_count, # Use actual count, not assumed
|
||||
point_count: actual_count, # Use actual count, not assumed
|
||||
point_ids_checksum: calculate_checksum(point_ids),
|
||||
archived_at: Time.current,
|
||||
metadata: {
|
||||
|
|
|
|||
|
|
@ -78,9 +78,7 @@ module Points
|
|||
# Report successful clear operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'clear',
|
||||
status: 'success',
|
||||
user_id: archive.user_id,
|
||||
points_count: cleared_count
|
||||
status: 'success'
|
||||
).call
|
||||
|
||||
# Report points removed (cleared from database)
|
||||
|
|
@ -95,8 +93,7 @@ module Points
|
|||
# Report failed clear operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'clear',
|
||||
status: 'failure',
|
||||
user_id: archive.user_id
|
||||
status: 'failure'
|
||||
).call
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,7 @@ module Points
|
|||
# Report successful restore operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'restore',
|
||||
status: 'success',
|
||||
user_id: user_id,
|
||||
points_count: total_points
|
||||
status: 'success'
|
||||
).call
|
||||
|
||||
# Report points restored (removed from archived state)
|
||||
|
|
@ -35,8 +33,7 @@ module Points
|
|||
# Report failed restore operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'restore',
|
||||
status: 'failure',
|
||||
user_id: user_id
|
||||
status: 'failure'
|
||||
).call
|
||||
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -52,8 +52,7 @@ module Points
|
|||
# Report successful verification operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'verify',
|
||||
status: 'success',
|
||||
user_id: archive.user_id
|
||||
status: 'success'
|
||||
).call
|
||||
|
||||
# Report verification duration
|
||||
|
|
@ -69,8 +68,7 @@ module Points
|
|||
# Report failed verification operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'verify',
|
||||
status: 'failure',
|
||||
user_id: archive.user_id
|
||||
status: 'failure'
|
||||
).call
|
||||
|
||||
# Report verification duration with check name
|
||||
|
|
@ -85,8 +83,7 @@ module Points
|
|||
# Report failed verification operation
|
||||
Metrics::Archives::Operation.new(
|
||||
operation: 'verify',
|
||||
status: 'failure',
|
||||
user_id: archive.user_id
|
||||
status: 'failure'
|
||||
).call
|
||||
|
||||
# Report verification duration
|
||||
|
|
|
|||
|
|
@ -9,7 +9,14 @@ FactoryBot.define do
|
|||
point_count { 100 }
|
||||
point_ids_checksum { Digest::SHA256.hexdigest('1,2,3') }
|
||||
archived_at { Time.current }
|
||||
metadata { { format_version: 1, compression: 'gzip' } }
|
||||
metadata do
|
||||
{
|
||||
format_version: 1,
|
||||
compression: 'gzip',
|
||||
expected_count: point_count,
|
||||
actual_count: point_count
|
||||
}
|
||||
end
|
||||
|
||||
after(:build) do |archive|
|
||||
# Attach a test file
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@ require 'prometheus_exporter/client'
|
|||
|
||||
RSpec.describe Metrics::Archives::Operation do
|
||||
describe '#call' do
|
||||
subject(:operation) { described_class.new(operation: operation_type, status: status, user_id: user_id).call }
|
||||
subject(:operation) { described_class.new(operation: operation_type, status: status).call }
|
||||
|
||||
let(:user_id) { 123 }
|
||||
let(:operation_type) { 'archive' }
|
||||
let(:status) { 'success' }
|
||||
let(:prometheus_client) { instance_double(PrometheusExporter::Client) }
|
||||
|
|
|
|||
Loading…
Reference in a new issue